#include <stdio.h>
#include <string.h>
void reverse(char str[], int i)
{int i=strlen(a);
char *s = a, *e = &a[i - 1], t;
while (e > s);
{t = *s;*s = *e;*e = t;
s++;e--;}}
int main()
{char a[1024];
int i = 0;
while (a[i] = getchar()! != '\n')
i++;
a[i] = '\0';
reverse(a);
puts(a);
return 0;}
修改见注释处,供参考:
#include <stdio.h>
#include <string.h>
void reverse(char str[])//修改
{
int i=strlen(str); //修改
char *s = str, *e = &str[i - 1], t; //修改
while (e > s) //; 修改
{t = *s;*s = *e;*e = t;
s++;e--;}
}
int main()
{
char a[1024];
int i = 0;
while ((a[i]=getchar()) && a[i] != '\n')//修改
i++;
a[i] = '\0';
reverse(a);
puts(a);
return 0;
}