下列程序中的函数strcpy2( )实现字符串两次复制,即将t所指字符串复制两次到s所指内存空间中,合并形成一个新字符串。例如:若t所指字符串为“efgh”,调用strcpy2后,s所指字符串为 “efghefgh”。请填空。void strcpy2(char *s, char *t){char *p = t;while(*s++ = *t++);s = ();while( () = *p++);}int main(void){char str1[100] = "abcd" , str2[ ] = "efgh";strcpy2(str1,str2); printf("%s\n", str1);return 0;}
查看答案
下列程序运行时如果从键盘输入字符串“qwerty”和“abcd”,则程序的输出结果是( )。int strle(char a[ ], char b[ ]){int num = 0,n = 0;while(*(a+num) != '\0') num++;while(b[n]) { *(a+num) = b[n]; n++; }return(num);}int main(void){char str1[81] , str2[81], *p1 = str1, *p2 = str2;gets(p1); gets(p2);printf("%d\n", strle(p1, p2)); return 0;}
阅读下列程序并回答问题。void funstr(char p[ ], char q[ ],int m){int k = strlen(q);for(;p[m] != '\0'; m++)q[m] = p[m]; /*第4行* /q[m] = '/0';}int main(void){char a[100] = "theVisualc++";char b[100] = "6.0";int m;scanf("%d", &m);funstr(a, b, m);puts(b); return 0;}(1) 程序运行时,输入3,输出();输入5,输出()。(2)将第4行改为“q[m-k] = p[m];”,程序运行时,输入3,输出()。
下面程序运行后输入g,输出是()。int main(void){int i;char s[ ] = "programming!", ch;printf("%d\t",sizeof(s));ch = getchar( ) ;for(i = 0; i < strlen(s); i++){if(s[i] == ch) { strcpy(s, s+i); puts(s); break; }}return 0;}
以下程序的功能是将无符号八进制数字构成的字符串转换为十进制整数。例如输入的字符串为556,则输出十进制整数366.请填空。int main(void){char *p, s[6];int n;p = s; gets(p);n = *p-'0';while(() != '\0') n = n*8 + *p - '0';printf("%d\n", n); return 0;}