坚持结构,获取和放置

stuck with structures, gets and puts

我坚持使用这个代码。
我将这个头文件 (header.h) 保存在我保存 main.c

的同一文件夹中
struct user{
     int userID;
     char firstName[30];
     char surName[30];
};

这是我的 main.c 文件,header.h 属于它。

#include <stdio.h>
#include <header.h>

int main()
{
    struct user Richard;
    struct user Kelvin;
    struct user Ann;

    Richard.userID = 1;
    Kelvin.userID = 2;
    Ann.userID = 3;

    puts("Enter the first name of user 1");
    gets(Richard.firstname);
    puts("Enter the Surname of user 1");
    gets(Richard.surname);

    puts("\n\nEnter the first name of user 2");
    gets(Kelvin.firstname);
    puts("Enter the Surname of user 2");
    gets(Kelvin.surname);

    puts("\n\nEnter the first name of user 3");
    gets(Ann.firstname);
    puts("Enter the Surname of user 3");
    gets(Ann.surname);

    printf("\n\n user 1 ID is %d \n", Richard.userID);
    printf("user 1 full name is %s %s. \n\n", Richard.firstname,Richard.surname);
    printf("user 2 ID is %d \n", Kelvin.userID);
    printf("user 2 full name is %s %s. \n\n",  Kelvin.firstname,Kelvin.surname);
    printf("user 3 ID is %d \n", Ann.userID);
    printf("user 3 full name is %s %s. \n", Ann.firstname,Ann.surname);
    return 0;
}

我使用代码块。此代码不 运行。当我 运行 此代码时,构建日志显示
fatal error: header.h: No such file or directory #include <header.h> 我找不到这段代码的错误。

不要使用 #include<header.h>

使用#include "header.h"

在您的 main.c 代码中,
#include <header.h> 替换为 #include "header.h"

在您的 header.c 代码中,
将姓氏替换为姓氏
将名字替换为名字

正如几个人指出的那样,您应该使用以下语法:

#include "header.h"

如果您在 #include 语法中使用尖括号,编译器会在系统目录中查找您的文件。

如果使用引号,编译器首先在 c 文件所在的同一目录中查找文件,只有在找不到时,才会在系统目录中查找。

您应该始终为您自己编写的文件使用引号。为标准库(以及 可能 其他库)保留尖括号。