Tôi đang tạo một hàm chỉ ghi "hello" vào một tệp. Tôi đã đặt nó trong một tập tin khác nhau và bao gồm tiêu đề của nó trong program.But gcc là đưa ra một lỗi cụ thể là: lỗi: unknown type name 'FILE'. Mã này được đưa ra dưới đâylỗi: tên loại không xác định ‘FILE’
app.c:
#include<stdio.h>
#include<stdlib.h>
#include"write_hello.h"
int main(){
FILE* fp;
fp = fopen("new_file.txt","w");
write_hello(fp);
return 0;
}
write_hello.h:
void write_hello(FILE*);
write_hello.c:
void write_hello(FILE* fp){
fprintf(fp,"hello");
printf("Done\n");
}
khi biên soạn bởi gcc sau đây xảy ra :
[email protected]:~/c/bank_management/include/test$ sudo gcc app.c
write_hello.c -o app
write_hello.c:3:18: error: unknown type name ‘FILE’
void write_hello(FILE* fp){
^
Xin lỗi vì bất kỳ sai lầm nào. Tôi là người mới bắt đầu.
'#include' từ 'write_hello.c' là tốt. 'FILE' được định nghĩa trong' stdio.h'. –