C言語基礎------ファイルからテキストfscanfを1行ずつ読む

713 ワード

#include
#include
const char * path="text.txt";
char s[2000];
char c;	
int main()
{
	
	FILE * fp=fopen(path,"r");
	if(fp==NULL)
		printf("error: file not found");
	/*
	  :scanf(%s)     fscanf(%c)  
			^
%c  
				windows    \r
( )
				linux: 
Mac:\r */ while(fscanf(fp,"%[^\r
]%c",&s,&c)!=EOF) { if(s!="") { fputs(s,stdout); printf("
"); memset(s,0,sizeof(char)); } else printf("error: no content"); } fclose(fp); return 0; }