函数strcat(str1,str2)实现将字符串str2中的大写字母拼接到字符串str1后面的功能。
char *strcat( char *str1, char *str2)
{ char *t=str1;
while (*str1!= '\0')
(1) ;
while ( *str2!= '\0' )
{
if((2) )
{ *str1=*str2; str1++; }
(3) ;
}
(4) ;
return(t);
}
#include<stdio.h>
char *strcat( char *str1, char *str2)
{ char *t=str1;
while (*str1!='\0')
str1++;
while (*str2!='\0'){
if(*str2>='A' && *str2<='Z')
{ *str1=*str2; str1++; }
str2++;
}
*str1='\0';
return(t);
}
int main(){
char a[] = "123456";
char b[] = "abcABC000DEF";
printf("%s",strcat(a,b));
return 0;
}
运行结果:
123456ABCDEF
Process exited after 1.242 seconds with return value 0
请按任意键继续. . .