我有这样的代码:不同的答案
//function to delete the occurence of c in s
void squeeze(char s[], int c) {
int i,j;
for(i=j=0;s[i]!='\0';i++)
if(s[i]!=c)
s[j++]=s[i];
s[j]='\0';
}
//function to concatenate string
void strca(char c[],char b[]){
int i,j;
i=j=0;
while(c[i]!='\0')
i++;
c[i++]=' ';
while((c[i++]=b[j++])!='\0')
;
}
现在,当我调用的函数在main()
int main(void){
1 char test[]="carmakarchile";
2 //squeeze(test,'a');
3 //printf("%s\n",test);
4 char f[]="Magnificent";
5 char n[]="King Rex";
6 strca(f,n);
7 squeeze(test,'a');
8 printf("%s\n",test);
9 printf("%s",f);
}
给出了OP:
King Rex Magnificent King Rex
虽然删除评论在2和3号线,并把评论7和8号线给我:
crmkrchile Magnificent King Rex
我只是想知道为什么和怎样的差别产生的?在此先感谢
哦..我知道了..谢谢很多:) – ejjyrex 2013-04-24 18:42:02