寰宇榛仁 2022-05-10 16:55 采纳率: 66.7%
浏览 8

C Primer Plus (第6版)中文版 P456中程序清单16.6/16.7/16.8 运行报错

C Primer Plus (第6版)中文版 P456中程序清单16.6/16.7/16.8 运行报错,出现语法错误,struct类型重定义等问题,麻烦各位该怎么修改

//names_st.h---names_st 结构的头文件
//常量
#include <string.h>
#define SLEN 32

//结构声明
struct names_st
{
    char first[SLEN];
    char last[SLEN];
};

//类型定义
typedef struct names_st_names;

//函数原型
void get_names(names *);
void show_names(const names *);
char* s_gets(char* st, int n);

//name_st.c---定义name_st.h中的函数
#include <stdio.h>
#include "name_st.h"
#include "useheader.c"

//函数定义
void get_names(names * pn)
{
    printf("Please enter your first name: ");
    s_gets(pn->first, SLEN);

    printf("Please enter your last name: ");
    s_gets(pn->last, SLEN);
}

void show_names(const names* pn)
{
    printf("%s %s", pn->first, pn->last);
}

char* s_gets(char* st, int n)
{
    char* ret_val;
    char* find;

    ret_val = fgets(st, n, stdin);
    if (ret_val)
    {
        find = strchr(st, '\n');
        if (find)
            *find = '\0';
        else
            while (getchar() != '\n')
                continue;
    }
    return ret_val;
}

//useheader.c---使用names_st结构
#include <stdio.h>
#include "name_st.h"
#include "name_st.c"

int main(void)
{
    names candidate;

    get_names(&candidate);
    printf("Let's welcome ");
    show_names(&candidate);
    printf(" to this program!\n");
    return 0;
}

  • 写回答

1条回答 默认 最新

  • kinghero123456 2022-05-10 17:02
    关注

    typedef struct names_st names;//你多加了一个下划线

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 5月10日

悬赏问题

  • ¥15 征集Python提取PDF文字属性的代码
  • ¥15 有偿求苍穹外卖环境配置
  • ¥15 代码在keil5里变成了这样怎么办啊,文件图像也变了,
  • ¥20 Ue4.26打包win64bit报错,如何解决?(语言-c++)
  • ¥15 clousx6整点报时指令怎么写
  • ¥30 远程帮我安装软件及库文件
  • ¥15 关于#自动化#的问题:如何通过电脑控制多相机同步拍照或摄影(相机或者摄影模组数量大于60),并将所有采集的照片或视频以一定编码规则存放至规定电脑文件夹内
  • ¥20 深信服vpn-2050这台设备如何配置才能成功联网?
  • ¥15 Arduino的wifi连接,如何关闭低功耗模式?
  • ¥15 Android studio 无法定位adb是什么问题?