Code::Blocks:带有指针 FILE 参数的函数(和函数原型)出错
Code::Blocks : Functions (and functions prototype) with the pointer FILE parameter get an error
所以我正在做一些基本的 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'
#include <stdio.h>
在您的 Functions.h 文件中
并将其修复为相同的 'functions' 和 'fonctions'
#ifndef __FUNCTIONS_INCLUDED__
#define __FONCTIONS_INCLUDED__
所以我正在做一些基本的 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'
#include <stdio.h>
在您的 Functions.h 文件中
并将其修复为相同的 'functions' 和 'fonctions'
#ifndef __FUNCTIONS_INCLUDED__
#define __FONCTIONS_INCLUDED__