小菜求助如何读完后如何停止
求助以下源码如何读完后如何停止
#include <stdio.h>
int main()
{
FILE *in;
int i;
int *a;
in=fopen("stdin.c","r");
for(;i!=EOF; i++)
{
fscanf(in,"%c",&a);
printf("%c\n",a);
}
fclose(in);
return 0;
}
读的系以下文件
#include <string.h>
#include <stdio.h>
int main(void)
{
FILE *stream;
char string[] = "This is a test";
char msg[20];
/* open a file for update */
stream = fopen("DUMMY.FIL", "w+");
/* write a string into the file */
fwrite(string, strlen(string), 1, stream);
/* seek to the start of the file */
fseek(stream, 0, SEEK_SET);
/* read a string from the file */
fgets(msg, strlen(string)+1, stream);
/* display the string */
printf("%s", msg);
fclose(stream);
return 0;
}
[ 本帖最后由 莫桑比克 于 2011-8-2 22:14 编辑 ]