-2
我试图从终端编译两个c文件时出现问题。 我拥有的文件是:main.c user_info.c。他们都在同一个文件夹中。 当尝试编译,我用:GCC的main.c user_info.c -o程序 它给出了一个错误消息: 的main.c:3:10:致命错误: 'user_info.h' 文件未找到编译两个c文件不能正常工作,找不到头文件
的main.c
#include <stdio.h>
#include <stdlib.h>
#include "user_info.h"
int main() {
struct user person1;
struct user person2;
person1.userId = 1;
person2.userId = 2;
puts("Enter the first name of user 1");
gets(person1.firstName);
puts("Enter the first name of user 2");
gets(person2.firstName);
printf("User 1 id is %d\n", person1.userId);
printf("User 2 first name is %s\n", person2.firstName);
return 0;
}
user_info.c
struct user {
int userId;
char firstName[25];
char lastName[25];
int age;
float weight;
};
如果实现文件包含'struct'声明,那么你的头文件包含了什么? – Olaf
如果没有使用该结构的单独源文件,则不需要标头。标题用于在源文件之间共享信息。但是,即使你现在不需要它,你也可以在将来做,或者它是你训练练习的一部分。 –