2、 设计一个函数f(char *p),对p指向的字符串进行逆序,要求函数f()中不能定义任何数组,不能调用任何字符串处理函数。在main()函数中,输入字符串,调用函数f(),最后输出逆序后的字符串。
#include<stdio.h>
#define N 10
typedef char Type;
void f(char* p)
{
int count=0;
Type* ptop = p;
while (*p!='\0')
{
count++;
p++;
}
Type* pend = ptop + (count-1);
while (ptop < pend)
{
Type temp = *ptop;
*ptop = *pend;
*pend = temp;
ptop++;
pend--;
}
}
int main()
{
Type a[N];
gets(a);
Type* p;
p = a;
f(p);
printf("%s", a);
return 0;
}