#include <stdio.h> #include <stdlib.h> #include <uuid/uuid.h> #include <string.h> void retrieveUuid(char *uuidValue) { uuid_t newUUID; uuid_generate(newUUID); uuid_unparse(newUUID,uuidValue); } void wf5(); void rf6(); int main() { wf5(); rf6(); } void rf6() { char *msg=(char*)malloc(255); FILE *fp=fopen("a.txt","r"); if(fp==NULL) { exit(EXIT_FAILURE); } int num=0; while (fgets(msg,255,fp)) { printf("I=%d,value=%sn",num++,msg); } fclose(fp); if(msg) { free(msg); } } void wf5() { char *msg=(char*)malloc(40); FILE *fp=fopen("a.txt","a+"); if(fp==NULL) { exit(EXIT_FAILURE); } for(int i=0;i<10000;i++) { retrieveUuid(msg); strcat(msg,"n"); fputs(msg,fp); } fclose(fp); if(msg) { free(msg); } }
Read file line by line
void rf7() { char *msg=(char*)malloc(255); FILE *fp=fopen("a.txt","r"); if(fp==NULL) { exit(EXIT_FAILURE); } int num=0; size_t len=0; while((getline(&msg,&len,fp))!=-1) { printf("Index=%d,value=%sn",num++,msg); } fclose(fp); if(msg) { free(msg); } }
原文链接: https://www.cnblogs.com/Fred1987/p/15582053.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;
也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/401799
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!