c prepend char * and fputs into file

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

void retrieveUuid2();
void file3();

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



void file3()
{
    FILE *fp=fopen("log.txt","w+");
    char *str1=(char*)malloc(40);
    char *numStr=(char*)malloc(6); 
    for(int i=0;i<100;i++)
    {
        char *str2=(char*)malloc(50);
        sprintf(numStr,"%d",i*i);
        strcat(numStr,",");
        retrieveUuid2(str1);
        strcat(str2,numStr);
        strcat(str2,str1);
        strcat(str2,"\n");
        printf("str=%s\n",str2);
        fputs(str2,fp); 
        free(str2);
    }
}

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

 

posted @ 2021-11-25 17:33  FredGrit  阅读(27)  评论(0编辑  收藏  举报