所以我在做一些基本的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'
答案 0 :(得分:1)
#include <stdio.h>
在Functions.h文件中
并将其修复为相同的“功能”和“功能”
#ifndef __FUNCTIONS_INCLUDED__
#define __FONCTIONS_INCLUDED__