其他分享
首页 > 其他分享> > C FILE fopen fputs strcat, write content to file via FILE;

C FILE fopen fputs strcat, write content to file via FILE;

作者:互联网

#include <stdio.h>
#include <stdlib.h>
#include <uuid/uuid.h>
#include <string.h>

void retrieveUuidVia(char *uuidValue)
{
    uuid_t newUUID;
    uuid_generate(newUUID);
    uuid_unparse(newUUID, uuidValue);
}


int main()
{
   
    FILE7();
    return 0;    
}

 void FILE7()
{
    FILE *fp = fopen("log.txt", "w+");
    if (fp == NULL)
    {
        exit(EXIT_FAILURE);
    }

    char *uuidStr = (char *)malloc(40);
    char *comma = ",";
    char *newLine="\n";

    for (int i = 0; i < 100000000; i++)
    {
        char *str = (char *)malloc(50);
        retrieveUuidVia(uuidStr);
        char *numStr = (char *)malloc(5);
        sprintf(numStr, "%d", i);
        strcat(numStr,comma);
        strcat(str,numStr);
        strcat(str,uuidStr);
        strcat(str,newLine);  
        fputs(str, fp);
        free(numStr);
        free(str);

        if (i % 1000000 == 0)
        {
            printf("I=%d\n", i);
        }
    }
    fclose(fp);
}

 

 

 

 

标签:fp,char,via,FILE,strcat,content,numStr,str,include
来源: https://www.cnblogs.com/Fred1987/p/15614834.html