69,381
社区成员
发帖
与我相关
我的任务
分享
//———names.h———————
#define SLEN 32
struct name_st
{
char first[SLEN];
char last[SLEN];
};
typedef struct name_st names;
void get_name(names *);
void show_name(names *);
#define SLEN 32
struct name_st { ... }; 和 typedef struct name_st names;
void get_name(names *);
void show_name(names *);
// a.c
#include <stdio.h>
#include "stdafx.h"
#include "names.h"
void get_name(names *pn)
{
int i;
printf("please enter the first name.\n");
fgets(pn->first, SLEN, stdin);
i = 0;
while(pn->first[i] != '\0' && pn->first[i] != '\n')
{
i++;
}
if(pn->first[i] == '\n')
{
pn->first[i] = '\0';
}
else
{
while(getchar() != '\n')
continue;
}
printf("please enter last name.\n");
fgets(pn->last, SLEN, stdin);
i = 0;
while(pn->last[i] != '\n' && pn->last[i] != '\0')
{
i++;
}
if(pn->last[i] == '\n')
{
pn->last[i] = '\0';
}
else
{
while(getchar()!= '\n')
continue;
}
}
void show_name(names *pn)
{
printf("%s %s", pn->first, pn->last);
}
//b.c
#include <stdio.h>
#include "stdafx.h"
#include "names.h"
int main(void)
{
names candidate;
get_name(&candidate);
printf("welcome to here.\n");
show_name(&candidate);
return 0;
}