第 1 頁:填空題 |
第 2 頁:改錯題 |
第 3 頁:程序題 |
請勿改動主函數(shù)main和其它函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入你編寫的若干語句。
給定源程序:
#include
#include
#define N 81
fun (char *s)
{
}
NONO()
{/* 請在此函數(shù)內(nèi)打開文件,輸入測試數(shù)據(jù),調(diào)用 fun 函數(shù),輸出數(shù)據(jù),關(guān)閉文件。 */
int i ;
char a[N] ;
FILE *rf, *wf ;
rf = fopen("in.dat","r");
wf = fopen("out.dat","w");
for(i = 0 ; i < 10 ; i++) {
fscanf(rf, "%s", a);
fun(a);
fprintf(wf, "%s\n", a);
}
fclose(rf);
fclose(wf);
}
main()
{char a[N];
printf ("Enter a string : "); gets (a);
printf ("The original string is : "); puts(a);
fun (a);
printf("\n");
printf ("The string after modified : ");
puts (a);
NONO();
}
參考答案:
fun ( char *s )
{
char b[N] ;
int i = 0, j ;
memset(b, 0, N) ;
for(j = strlen(s) - 1 ; j >= 0 ; j--) b[i++] = s[j] ;
strcpy(s, b) ;
}
相關(guān)推薦:北京 | 天津 | 上海 | 江蘇 | 山東 |
安徽 | 浙江 | 江西 | 福建 | 深圳 |
廣東 | 河北 | 湖南 | 廣西 | 河南 |
海南 | 湖北 | 四川 | 重慶 | 云南 |
貴州 | 西藏 | 新疆 | 陜西 | 山西 |
寧夏 | 甘肅 | 青海 | 遼寧 | 吉林 |
黑龍江 | 內(nèi)蒙古 |