|
楼主 |
发表于 2006-6-30 14:18:51
|
显示全部楼层
#include "stdio.h"
main()
{
char key;
FILE *stream; /*流的指针*/
printf("please input a letter \n");
key=getchar(); /*读入一个字符*/
//if(stream=fopen("test","r")==(FILE*)0) /*将流与一个文件联系起来*/
if ((stream=fopen("test","r"))==NULL)
{
//判断是否成功
fprintf(stderr,"Error opening file.\n");
exit(1);
}
/*将缓冲区设定为行缓冲,并判断是否成功*/
if (setlinebuf(stream))!=0)
{
printf(stderr,"Error setlinebuffer/\n");
exit(1);
}
/*将对应缓冲区清空,并判断操作是否成功*/
if (fpurge(stream))==EOF)
{
fprintf(stderr,"Error flush stream.\n");
exit(1);
}
/*对流读写操作*/
fprintf(stream,"The letter that you input is %c .\n",Key);
/*在程序结束之前关闭流,并判断操作是否成功*/
if(fclose(stream))==EOF)
{
fprintf(stderr,"Error closing file \n");
exit(1);
}
}
编译时出现的信息是:
[root@localhost linuxss]# gcc -ggdb3 -o text3 text3.c
text3.c: In function `main':
text3.c:22: void value not ignored as it ought to be
text3.c:22: parse error before '!=' token
text3.c: At top level:
text3.c:30: parse error before "if"
text3.c:33: parse error before numeric constant
text3.c:33: warning: data definition has no type or storage class
text3.c:38: parse error before string constant
text3.c:38: warning: conflicting types for built-in function `fprintf'
text3.c:38: warning: data definition has no type or storage class
text3.c:45: parse error before numeric constant
text3.c:45: warning: data definition has no type or storage class
text3.c:51:1: warning: no newline at end of file
[root@localhost linuxss]#
各位大哥,我需要修改哪些东西呢?
谢谢! |
|