#include <stdio.h>
#include <stdlib.h>
#include "names_st.h"
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
names candidate;
get_names(&candidate);
printf("Let` s welcome ");
show_names(&candidate);
printf(" to this program!\n");
return 0;
}
#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 *);
#include <stdio.h>
#include "names_st.h"
void get_names(names * pn){
int i;
printf("Please enter your first name :");
fgets(pn->first,SLEN,stdin);
i = 0;
while(pn->first[i] != '\n' && pn->first[i] != '\0')
i++;
if (pn->first[i] == '\n')
pn->first[i] = '\0';
else
while (getchar() != '\n')
continue;
printf("Please enter your last name: ");
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_names(const names * pn){
printf("%s %s",pn->first,pn->last);
}
PS:附件的工程编译通过