names_st.c
来自「经典书籍:C Primer Plus(第五版)中文版和源代码 本书全面讲述了C」· C语言 代码 · 共 38 行
C
38 行
// names_st.c -- define names_st functions
#include <stdio.h>
#include "names_st.h" // include the header file
// function definitions
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);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?