Function to achieve string in reverse
The title string required to achieve a simple function of reverse.
Function interface definition:
void f( char *p );
Function f p string pointed to perform reverse operation. Required function f defined in any array can not call any string functions.
Sample input:
Hello World!
Sample output:
!dlroW olleH
#include <stdio.h>
#define MAXS 20
void f( char *p );
void ReadString( char *s ); /* 由裁判实现,略去不表 */
int main()
{
char s[MAXS];
ReadString(s);
f(s);
printf("%s\n", s);
return 0;
}
void f( char *p )
{
int i=0,q=0,h,huan;
while(p[i]!='\0')
i++;
h=i-1;
while(q<=h)
{
huan=p[q];
p[q]=p[h];
p[h]=huan;
q++;
h--;
}
return ;
}