下列选项中,不能将字符串from复制给字符数组to的是( )。
A: void copy_string(char to[ ], char from[ ]) { int i=0; while (from[i]!='\0') { to[i]=from[i]; i++; } to[i]='\0'; }
B: void copy_string(char *to, char *from) { for ( ; *from!='\0'; from++, to++) *to=*from; }
C: void copy_string(char *to, char *from) { while ( (*to=*from)!='\0' ) { to++; from++; } }
D: void copy_string(char *to, char *from) { while (*to++=*from++); }
A: void copy_string(char to[ ], char from[ ]) { int i=0; while (from[i]!='\0') { to[i]=from[i]; i++; } to[i]='\0'; }
B: void copy_string(char *to, char *from) { for ( ; *from!='\0'; from++, to++) *to=*from; }
C: void copy_string(char *to, char *from) { while ( (*to=*from)!='\0' ) { to++; from++; } }
D: void copy_string(char *to, char *from) { while (*to++=*from++); }
举一反三
- Complete the following function: /* copy string2 to string1 */ void strcopy(char string1[], char string2[]) { int i = 0; while (string2[i] != '\0') { string1[i] = string2[i]; i++; } ____<br/>}[/i][/i][/i] A: return; B: string1[i - 1] = '\0'; C: string1[i] = '\0'; D: string1[i + 1] = '\0';
- 合法的数组定义是( ) 。 A: char a[ ] = {‘s’, ‘t’, ‘r’, ‘i’, ‘n’, ‘g’, 0}; B: char s = "string"; C: char a[ ] = {‘s’, ‘t’, ‘r’, ‘i’, ‘n’, ‘g’, ‘\0’};<br>char a[] = "string";
- Which can replace lines 5 and 6 in the following function ? 1 /* copy string2 to string1 */ 2 void strcopy(char string1[], char string2[]) 3 { 4 int i = 0; 5 while (string1[i] = string2[i]) 6 i++; 7 }[/i][/i] A: while (*string1 = *string2) ; B: while (*string1 = string2) ; C: while (*string1++ = *string2++) ; D: while (*++string1 = *++string2) ;
- 分析以下4个strcpy函数,其功能是把字符串 s2复制到串s1中,正确的是( )。 (1) strcpy(char s1[],char s2[]) { int i=0; while((s1[i]=s2[i])!='\0')i++; } (2) strcpy(char *s1,char *s2) { while(*s1++=*s2++); } (3) strcpy(char *s1,char *s2) { while((*s1=*s2)!=’\0’) { s1++; s2++; } } (4) strcpy(char *s1,char *s2) { while((*s1++=*s2++)!=‘\0’); }
- 下面字符数组初始化语句正确且与语句char c[]="string";等价的是( ) 。 A: char c[]={'s','t','r’,'i’,'n','g'}; B: char c[]={'s','t','r’,'i’,'n','g','\0'}; C: char c[]={'string'}; D: char c[]='string';