The following code with function call can shift a string but the code
without function call can not. What might be the problem? Thanks!
_______________________________________________________
void shift(char a[])
{
int i=0;
while(a[i]) a[i] = a[++i];
}
int main()
{
char str[]= "afdd";
shift(str);
cout<
return 0;
}
_____________________________________________________________
int main()
{
char str[]= "afdd";
int i=0;
while(str[i]) str[i] = str[++i];
cout<
return 0;
}
___________________________________________
p***o 发帖数: 1252
2
a[i]=a[++i] is undefined. Change it to {a[i]=a[i+1];++i;}
【在 h**l 的大作中提到】 : The following code with function call can shift a string but the code : without function call can not. What might be the problem? Thanks! : _______________________________________________________ : void shift(char a[]) : { : int i=0; : while(a[i]) a[i] = a[++i]; : } : int main() : {
h**l 发帖数: 168
3
I see. Thanks.
【在 p***o 的大作中提到】 : a[i]=a[++i] is undefined. Change it to {a[i]=a[i+1];++i;}