Unknown type name file

I am making a function which is just writes "hello" to a file. I have put it in a different file and included its header in the program.But gcc is giving an error namely: error: unknown type name ‘FILE’. The code is given below

when compiling by gcc the following occurs:

Sorry for any mistakes.I am a beginner.

1 Answer 1

FILE is defined in stdio.h and you need to include it in each file that uses it. So write_hello.h and write_hello.c should both include it, and write_hello.c should also include write_hello.h (since it implements the function defined in write_hello.h).

Also note that it is standard practice for every header file to define a macro of the same name (IN CAPS), and enclose the entire header between #ifndef, #endif. In C, this prevents a header from getting #included twice. This is known as the "internal include guard" (with thanks to Story Teller for pointing that out). All system headers such as stdio.h include an internal include guard. All user defined headers should also include an internal include guard as shown in the example below.

write_hello.h

write_hello.c

Note that when you include system files, the header name is placed within <> ‘s. This helps the compiler identify that these headers are system headers which are stored in a central place based on your development environment.

Your own custom headers are placed in quotes "" are typically found in your current directory, but may be placed elsewhere by including the path, or adding the directory to your list of directories that the compiler searches. This is configurable within your project if you are using an IDE like NetBeans, or using the -I compiler option is building it directly or through a makefile.

Читайте также:  Function is not defined javascript

Пробую вкомпилировать jansson (парсер json) в свой проект (с++) . Выдает ошибку Unknown type name ‘uint32_t’.

  • Вопрос задан более трёх лет назад
  • 8038 просмотров

попробуйте подключить заголовок stdin.h или объявить этот тип так:

а если без без директив препроцессора: просто typedef unsigned int uint32_t;

причем это должно в том файле быть, где ругается на отсуствие типа.

Я делаю функцию, которая просто пишет "hello" в файл. Я поместил его в другой файл и включил его заголовок в программу. Но gcc дает ошибку, а именно: error: unknown type name ‘FILE. Код приведен ниже

при компиляции с помощью gcc происходит следующее:

Извините за любые ошибки. Я начинаю.

FILE определяется в stdio.h, и вам нужно включить его в каждый файл, который его использует. Поэтому write_hello.h и write_hello.c должны оба включить его, а write_hello.c также должен включать write_hello.h(поскольку он реализует функцию, определенную в write_hello.h).

Также обратите внимание, что стандартная практика для каждого файла заголовка определять макрос с тем же именем (IN CAPS) и заключить весь заголовок между #ifndef, #endif. В C это предотвращает получение заголовка дважды. Это известно как "внутренний охранник" (благодаря Story Teller для указания этого).

Rate this post

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *