原代码是这样的:
#include <stdio.h>
int main( void )
{
char c, stmp, array[80];
int i=0, j;
while ((c=getchar()) != '\n')
{array[i++] = c;
array[i] = '\0';}
for (j=i-1; j>=i/2; j--)
{
stmp = array[j];
array[j] = array[i-1-j];
array[i-1-j] = stmp;
}
printf("\n");
for (i=0; array[i]!='\0'; i++)
printf("%c",array[i]);
return 0;
}
本人改过后:
#include <stdio.h>
int main( void )
{
char c, stmp, array[80];
int i=0, j;
while ((c=getchar()) != '\n')
{array[i++] = c;
array[i] = '\0';}
for (j=i; j>=0; j--)
{
printf("%c",array[j]);
}
return 0;
}
执行结果一样啊!难道书上讲的也有错?
#include <stdio.h>
int main( void )
{
char c, stmp, array[80];
int i=0, j;
while ((c=getchar()) != '\n')
{array[i++] = c;
array[i] = '\0';}
for (j=i-1; j>=i/2; j--)
{
stmp = array[j];
array[j] = array[i-1-j];
array[i-1-j] = stmp;
}
printf("\n");
for (i=0; array[i]!='\0'; i++)
printf("%c",array[i]);
return 0;
}
本人改过后:
#include <stdio.h>
int main( void )
{
char c, stmp, array[80];
int i=0, j;
while ((c=getchar()) != '\n')
{array[i++] = c;
array[i] = '\0';}
for (j=i; j>=0; j--)
{
printf("%c",array[j]);
}
return 0;
}
执行结果一样啊!难道书上讲的也有错?