#include<stdio.h>
#include<string.h>
#include<stdlib.h>
const int maxn = 10;
int main()
{
char s[1024] = {0};
FILE *p = fopen("/home/exbot/wangqinghe/C/20190716/file.txt","r");
//第一個參數是一個記憶體位址,第二個參數是這塊記憶體的大小,
//第三個參數是fopen傳回的檔案指針
fgets(s,maxn,p);
printf(" s = %s\n",s);
fclose(p);
return 0;
}
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
const int maxn = 10;
int main()
{
char s[1024] = {0};
FILE *p = fopen("/home/exbot/wangqinghe/C/20190716/file.txt","r");
//feof(p) p檔案到尾部則傳回正
while(!feof(p))
{
memset(s,0,sizeof(s));
fgets(s,sizeof(s),p);
printf("%s\n",s);
}
fclose(p);
return 0;
}