6-2 函式實現字串逆序(10 分)
阿新 • • 發佈:2019-02-11
本題要求實現一個字串逆序的簡單函式。
函式介面定義:
void f( char *p );
函式f對p指向的字串進行逆序操作。要求函式f中不能定義任何陣列,不能呼叫任何字串處理函式。
裁判測試程式樣例:
本題要求實現一個字串逆序的簡單函式。
函式介面定義:
void f( char *p );
函式f對p指向的字串進行逆序操作。要求函式f中不能定義任何陣列,不能呼叫任何字串處理函式。
裁判測試程式樣例:
#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;
}
/* 你的程式碼將被嵌在這裡 */
輸入樣例:
Hello World!
輸出樣例:
!dlroW olleH
輸入樣例:
Hello World!
輸出樣例:
!dlroW olleH
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 ;
}