怎么连接两个字符串
答:1)简单来,直接用 strcat 函数,需要包含头文件 string.h2)自己实现的话也不麻烦,但是要考虑一些细节:假设两个字符串指针为 str1,str2 ,现在要讲 str1 和 str2 连接成一个新的字符串。a.考虑指针 str1,str2 是否非空b.如果将str2的内容直接连接到str1的末尾,要考虑str1是否有足够的剩余...
答:先加头文件#include\x0d\x0achar a[10]="123";\x0d\x0a char b[10]="abc";\x0d\x0a strcat(a,b); //连接两个字符串,连接后的字符串存放在a中,数组a中有足够空间\x0d\x0a printf("%s",a); //输出连接后的字符串\x0d\x0a\x0d\x0a或:\x0d\x0a#include...
答:void fun (char s1[],char s2[]){ int i,j;for (i=0;s1[i] !=’\0’; i++); /*求出的i为pA字符的总长度,包括结束标记位*/ for (j=0;s2[j] !=’\0’; j++)s1[i++]=s2[j]; /*将pB字符串连在pA字符串的后面*/ s1[i]='\0’; /*在字符串最后加上结束标记符*...
答:1、实际上就是实现strcat这个字符串库函数,在vc自带的crt源码或者linux平台的glibc库中都有strcat的源码,自己可以查阅参考,看看库开发者是如何写代码的,对于学习C语言非常有用。2、示例 include <stdio.h> char *strcat(char *str1, char *str2){ if((str1==NULL)||(str2==NULL)) throw "...
答:1、首先我们比较常用的是fprintf函数,如下图所示,但是它连变量名称也打印出来了。2、然后我们用disp函数输出的时候就可以只打印值了。3、接下来我们将三个字符串放在disp函数中,如下图所示,disp函数将他们连接在了一起。4、如果想让字符串之间有空格的话可以在字符串中加入空格。5、接下来我们将...
答:include<stdio.h> void main(){ char s1[80],s2[40];int i=0,j=0;printf("\ninput stringl:");scanf("%s",s1);printf("input string2:");scanf("%s",s2);while(s1[i]!='\0')i++;while(s2[j]!='\0')s1[i++]=s2[j++];s1[i]='\0';printf("The new string is:%s...
答:1、新建一个工程和.c文件 ,输入头文件和主函数。2、定义变量类型。3、调用cpy函数。4、定义一个函数,并定义变量类型。5、用一个For 语句和if语句判断是否为元音。6、最后加一个字符串结束符,并在主函数中输出。7、编译。运行得到最后结果。
答:如果只传人一个参数,如果参数是字符串,就返回该字符串;如果是非字符串,那么就调用相应类型的 ToString()方法,把该参数转换为字符串返回。如果传人多个参数,Concat 把各个字符串连接在一起返回,如果传人的参数不全是string类型,则不是字符串类型的参数,调用相应的 ToString()方法首先转化为字符串...
答:这样就可以了,我已经在vc6通过调试运行了,不过要注意一点哦,虽然c语言里面没有string类型的变量,但是在c++里面有,所以为了防止不必要的麻烦,你这里的变量名字最好不要用string include<stdio.h> void stringcat(char str1[],char str2[],char str[]){ int i,j;for(i=0;str1[i]!='\0...
答:代码:char str1="123";char str2="abc";strcat(str1,str2);printf("%s",str1);例如:include <stdio.h> include <string.h> main(){ char strDes[N]= "kkkjdah", strSor[N]="sdasdaaa";strcat(strSor,strDes);//链接 puts(strDes);puts(strSor);} ...
网友评论:
查狗19772005433:
用C语言怎么将两个字符串连接起来? -
13434齐朱
: 这些是宏的功能. #是将一个参数转换为字符串.##可以连接字符串比如这样: #include <stdio.h> #define STR(a,b) a##b int main() { printf("%s\n",STR("123","456")); return 0; }
查狗19772005433:
将两个字符串连接起来 -
13434齐朱
: 引数void *mystrcat(char* s1, char* s2) 第一个引数输入在函数外部 char *a="asdfasdf" 声明 编译通过但是运行会出现错误 (*a 指向的内容被视为是常量,不可改变) 或者 char a[]="ab",也会出错,(长度超限,运行时错误) 除非char a[...
查狗19772005433:
如何将两个字符串相连接啊,急!!! -
13434齐朱
: 可以使用strcat();函数,具体例子: #include <string.h> #include <stdio.h> void main( void ) { char string[80]; strcpy( string, "Hello world from " ); strcat( string, "strcpy " ); strcat( string, "and " ); strcat( string, "strcat!" ); printf( "String = %s\n", string ); } 输出结果:String = Hello world from strcpy and strcat!
查狗19772005433:
如何连接两个字符串? -
13434齐朱
: CONCAT(CHAR1,CHAR2)SELECT CONCAT('ABC','DEFGH') FROM DUAL;结果: 'ABCDEFGH'
查狗19772005433:
C语言中 怎么连接两个字符串? -
13434齐朱
: 注意,下面这句 i++ ,如果a数组中取出的 不是 '\0' (结束符)的话, i 加 1 了 , while(a[i]!='\0') i++; // 所以 下面这句执行 时, i 应该 是 10 (左右),就是 hello word 结束后 while(b[j]!='\0') 所以不会覆盖 a 数组中原有数据
查狗19772005433:
在C语言编程中,如何利用调用函数来把两个字符串连接起来? -
13434齐朱
: strcat(a,b)把字符串b连到字符串a后面 举例; strcat("wo","niu");//输出woniu
查狗19772005433:
编一个程序,将两个字符串连接起来,不要用strcat函数,越简单的越好. -
13434齐朱
: #include int main() { char str1[100],str2[100]; char *p=str1; char *q=str2; printf("please enter str1:"); scanf("%s",str1); printf("please enter str2:"); scanf("%s",str2); while (*p!='\0') //让指针指向p的最后一个 { p++; } while (*q!='\0')//从p指针...
查狗19772005433:
用strcat函数把两个字符串连起来 -
13434齐朱
: strcat(连接两字符串) 相关函数bcopy,memccpy,memcpy,strcpy,strncpy 表头文件#include <string.h> 定义函数char *strcat (char *dest,const char *src); 函数说明strcat()会将参数src字符串拷贝到参数dest所指的字符串尾.第一个参数dest...
查狗19772005433:
用C语言写出一函数,将两个字符串连接,该怎么写 -
13434齐朱
: void concat(char *s1, int size1, char *s2, int size2, char *sout) {int i;for (i = 0; i < size1; ++i)sout[i] = s1[i];for (i = 0; i < size2; ++i)sout[i + size1] = s2[i];sout[i] = '\0'; } 示例使用方法: char *s1 = "ABCD"; char *s2 = "12345"; char sout[100];...
查狗19772005433:
怎样将两串字符串连接在一块不用string函数 -
13434齐朱
: int stringcat(char* ds,char* sr)//把sr拷贝到ds后面 { int cnt=0; char* tmd,*tms; tmd=ds; tms=sr; while(*tmd++!='\0'); tmd--; while((*(tmd++)=*tms++)!='\0')cnt++; return cnt; }