Whai
Whai

Reputation: 3

Code::Blocks : Functions (and functions prototype) with the pointer FILE parameter get an error

So I was doing some basic C then I'm blocked.

I wanted to count lines in a file. Function and prototype function are in .c (for the function) and in .h (for the prototype function), the problem is I get errors

Note : I use the compiler GNU GCC C++ 14 ISO

From 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;
}

From Function.h :

#ifndef __FUNCTIONS_INCLUDED__
#define __FONCTIONS_INCLUDED__

int FileLineCount(FILE *file);

#endif

From the 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));
}

Here is the error from the compiler :

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

Upvotes: 0

Views: 262

Answers (1)

Spinkoo
Spinkoo

Reputation: 2080

#include <stdio.h>

in your Functions.h file

and fix this to be the same 'functions' and 'fonctions'

#ifndef __FUNCTIONS_INCLUDED__
#define __FONCTIONS_INCLUDED__ 

Upvotes: 1

Related Questions