Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

problem writting a struct at file

$
0
0

Hello,

I am creating an  mfc application where a struct

struct CallLogEntry
{
    string name,phoneNumber,time;
    int duration;
};

i am writting this struct to file by using following method:

    void write(CallLogEntry c)
    {
        //contactList.push_back(c);
        char szPath[MAX_PATH];    
        SHGetFolderPathA(NULL,CSIDL_APPDATA,NULL,0,szPath );
        strcat(szPath,fileName1);
    
        FILE *fp = fopen(szPath, "a");
        fwrite(&c,sizeof(CallLogEntry),1,fp);    
        fclose(fp);

    }

        callLogEntry.phoneNumber=str_dest_no;
        callLogEntry.time = this->currentDateTime();
        callLogEntry.name="";


        callLogController.write(callLogEntry);

    const std::string currentDateTime() {
        time_t     now = time(0);
        struct tm  tstruct;
        char       buf[80];
        tstruct = *localtime(&now);
        // Visit http://www.cplusplus.com/reference/clibrary/ctime/strftime/
        // for more information about date/time format
        strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);

        return buf;
    }

but it is not writting at file properly and I am not getting the time properly after reading from file.


jamil


Viewing all articles
Browse latest Browse all 15302

Trending Articles