Code :: Blocks: функции (и прототипы функций) с указателем параметра FILE получают ошибку - PullRequest
0 голосов
/ 26 января 2019

Итак, я делал базовый C, а потом меня заблокировали.

Я хотел посчитать строки в файле. Функция и функция-прототип находятся в .c (для функции) и в .h (для функции-прототипа), проблема в том, что я получаю ошибки

Примечание: я использую компилятор GNU GCC C ++ 14 ISO

Из Function.c:

#include "Functions.h"

int FileLineCount(FILE *file)
{
    rewind(file);

    int iCount = 0;
    char string[MAX_CHARACTER_SIZE] = "";

    while((fgets(string, MAX_CHARACTER_SIZE, file) != NULL))
    {
        iCount++;
    }

    return iCount;
}

из Function.h:

#ifndef __FUNCTIONS_INCLUDED__
#define __FONCTIONS_INCLUDED__

int FileLineCount(FILE *file);

#endif

Из main.c:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "Functions.h"

#define MAX_CHARACTER_SIZE 256

int main()
{
    FILE *WordsFile = NULL;
    const char strWorldFileName[] = "RandomWords.txt";
    WordsFile = fopen(strWorldFileName, "r");

    if(WordsFile == NULL)
    {
        printf("Error ! Impossible to open the file %s\n", strWorldFileName);
        printf("Verify if this .txt file is in the folder where the file main.c is in it\n");
        return EXIT_FAILURE;
    }

    printf("Line count : %i\n\n", FileLineCount(WordsFile));
}

Вот ошибка от компилятора:

error: unknown type name 'FILE'
error: unknown type name 'FILE'

1 Ответ

0 голосов
/ 26 января 2019
#include <stdio.h>

в вашем файле Functions.h

и исправьте так, чтобы это были те же «функции» и «функции»

#ifndef __FUNCTIONS_INCLUDED__
#define __FONCTIONS_INCLUDED__ 
...