文件操作(读)
讀一行:
#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; }?
轉載于:https://www.cnblogs.com/wanghao-boke/p/11196806.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
- 上一篇: win10电脑如何无线投屏电视
- 下一篇: 时间都知道剧情介绍