当前位置: 首页> 健康> 母婴 > 连接字符串——strcat函数

连接字符串——strcat函数

时间:2025/8/23 9:10:09来源:https://blog.csdn.net/qq_69383179/article/details/140143003 浏览次数:0次

目录

  • 开头
  • 1.``strcat``函数的基本介绍
  • 2.``strcat``函数的内部构造和流程图
    • ``strcat``函数的内部构造
    • ``strcat``函数的流程图
  • 3.``strcat``函数的实际运用(这里只列举其二)
    • 后室层级传送器(不能去隐秘层级)
    • 浏览器
  • 结尾

开头

大家好,我叫这是我58。今天,我们来认识一下C语言中的strcat函数。

1.strcat函数的基本介绍

strcat函数,是来自于<string.h>头文件的函数,用来连接两个字符串,连接好之后就返回被连接的字符串,其中,strcat函数的构造是这样的。

char * strcat ( char * 要被连接的字符串, const char * 要连接的字符串 );

1

2.strcat函数的内部构造和流程图

strcat函数的内部构造

char* strcat(char* d, const char* s) {while ('\0' != *d) {d++;}for (; '\0' != *s; (d++,s++)) {*d = *s;}*d = '\0';return d;
}//这里的“要被连接的字符串”和“要连接的字符串”分别简化成了“d”和“s”,因为“destination”和“source”

strcat函数的流程图

返回d
开始
'\0' != *d?
d自增1
'\0' != *s?
设解引用的d为解引用的s
d自增1,s自增1
设解引用的d为“\0”
结束

3.strcat函数的实际运用(这里只列举其二)

后室层级传送器(不能去隐秘层级)

#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {char str[60] = "start https://backrooms-wiki-cn.wikidot.com/level-";char stra[10] = "";printf("直接输入数字即可传送到普通的与这个数字对应的层级,如果前缀有“c-”还可以传送到我们中国人原创的与这个前缀后面的数字对应的层级 -> ");scanf("%s", stra);strcat(str, stra);system(str);return 0;
}

浏览器

#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {int i = 0;char str[10000] = "";char stra[13] = "https://www.";char strb[10000] = "start ";printf("可以搜索或者输入网址(在Bing里搜索) -> ");scanf("%s", str);for (i = 0; i < 8; i++) {if (str[i] != stra[i]) {break;}}if (8 != i) {for (i = 0; i < 4; i++) {if (str[i] != stra[i + 8]) {break;}}strcat(strb, "https://");if (4 != i) {strcat(strb, "cn.bing.com/search?q=");}}strcat(strb, str);system(strb);return 0;
}

结尾

在看到这里之后,我想你们应该都认识了这个strcat函数吧,那么,如果你喜欢这篇博客里的strcat函数,可以评论或者投票来互动一下我哦。


  1. 选自strcat函数的简介 ↩︎

关键字:连接字符串——strcat函数

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: