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;
}
typedef struct names_st names;//你多加了一个下划线