C write and read file via FILE and open method in a+ or r mode

#include <iostream>
#include <uuid/uuid.h>
#include <time.h>
#include <unistd.h>
#include <fstream>
#include <istream>
#include <ostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

void readFile8()
{
    FILE *fp=fopen("log2.txt","r");
    if(!fp)
    {
        printf("Create or open log2.txt failed!\n");
    }

    char *uuidValue=(char*)malloc(40);
    size_t len=40; 
    int num=0;
    while((getline(&uuidValue,&len,fp))!=-1)
    {
        printf("Num=%d,value=%s\n",num++,uuidValue);
    }
    fclose(fp);
    free(uuidValue);
    printf("Finished!\n\n");
}

void writeFile7()

The effect as below snapshot.

Similar Posts: