Search code examples
carraysfilefwritefread

fread not loading in whats in my binary file?


Basically, I've written text to a file and heard that it is similar steps to fread the contents back into my array at the start of the program but nothing is read back in. Here is my code

void backUp(PAYROLL employee[], long int *pCounter)
{
    FILE *record;
        errno_t result = fopen_s(&record, "c:\\record.bin", "a+b");
    if (record != 0){
        fwrite(employee, sizeof(PAYROLL), 1 , record);
        fclose(record);
    }
}

void upload(PAYROLL employee[], long int *pCounter)
{

    FILE *record;
    errno_t result = fopen_s(&record, "c:\\record.bin", "r+b");
    if (record != 0)
    {
        fread(employee, sizeof(PAYROLL), 1, record);
        fclose(record);
    }
}

Solution

  • To create and update a file in the root directory of the system drive, it is necessary to the execution of the program at a command prompt for the administrator.
    So, the program have failed to do.

    To do this, you want to change the creation of the file to the user directory, or there is a need to run the program by invoking the administrative command prompt.