【说明】
以下程序的功能是:从键盘上输入一个字符串,把该字符串中的小写字母转换为大写字母,输出到文件test.txt中,然后从该文件读出字符串并显示出来。
【程序】
#include < stdio. h >
main( )
FILE * fp;
char str[100]; int i=0;
if((fp=fopen("text.txt" (1) )) ==NULL)
printf("can’t open this file. \n") ;exit(0) ;
printf(" input astring: \n" ); gest(str);
while( str[i] )
if(str[i] >=’a’ && str[i] <=’z’)
str[i]= (2) ;
fputc(str[i], (3) );
i++;
fclose(fp);
fp=fopen(" test.txt", (4) );
fgets(str, 100, fp);
printf("%s\n" ,str);
(5) ;