标识符“ FILE”未定义

时间:2019-06-16 14:20:47

标签: c

我编写了将文件保存为二进制文件的函数,但出现一个错误:

  

标识符“ FILE”未定义

我在Visual Studio中工作,我知道有时问题是由Visual引起的。

void menuMENU() {
    char FileName[] = "binaryFile.bin";
    MY_STACK * tmp = NULL;
    KIERUNEK_STUDIOW kierunek;
    int number;
    char input = ' ';
    MY_STUD *student = NULL;

    while (input) {
        input = menuText();
        switch (input) {
        case 'a':
            student = (MY_STUD*)malloc(sizeof(MY_STUD));
            init(student);
            fillStudent(student);
            stud=addObject(stud,student);
            printStack(stud);
            if (!student) {
                errorMessage();
                student = (MY_STUD*)malloc(sizeof(MY_STUD));
            }

            stdinClear();
            //enter a student
            break;
        case 'd':
            popFromStack(& stud);
            stdinClear();
            break;
        case 'f': 
            findStud(stud);
            stdinClear();
                  break;
        case 'r':
            readMyStack(&stud, FileName);
            break;
        case 's':
            saveBinary(&stud, FileName);
            break;
        case 'e':
            exit(0);
            break;
        default:
            printf("Unknown command");
        }

    }
}


//function to save file

void saveBinary(MY_STACK** last, char * filename) {
    size_t num = numberOfElements(*last);

    size_t it = 0;
    unsigned int no_it = (unsigned int)num;
    MY_STACK tmp;

    if (!num) {
        printf("Stack is empty.\n");
        return;
    }
    else {
        __int64 *fileMemory = (__int64 *)malloc((num + 1) * sizeof(__int64));
        if (!fileMemory) {
            errorMessage();
        }

        FILE *pf;
        errno_t error;
        if ((error = fopen_s(&pf, filename, "wb")) != 0) {
            errorMessage();
        }

        if (fwrite(&no_it, sizeof(unsigned int), 1, pf) != 1) {
            errorMessage();
        }
        _fseeki64(pf, (num + 1) * sizeof(__int64), SEEK_CUR);
        for (it = 0; it < num; ++it) {
            tmp = popFromStack(last);

            fileMemory[it] = ftell(pf);

            (*(tmp.ptrToSaveBinary))(tmp.ptrToData, pf);
        }

        fileMemory[it] = ftell(pf);

        _fseeki64(pf, sizeof(unsigned int), SEEK_SET);
        if (fwrite(fileMemory, sizeof(__int64), num + 1, pf) != num + 1) {
            errorMessage();
        }

        if (pf)
            fclose(pf);
        pf = NULL;

        if (fileMemory)
            free(fileMemory);
        fileMemory = NULL;

        printf("Stack is saved to binary file.\n");
    }
}

0 个答案:

没有答案