一個計科小白的每日編程打卡18.07.27
/*name1.c ---使用指向結構的指針*/
#include<stdio.h>
#include<string.h>
#define NLEN 30
struct namect{
char fname[NLEN];
char lname[NLEN];
int letters;
};
void getinfo(struct namect *);
void makeinfo(struct namect *);
void showinfo(struct namect *);
char *s_gets(char * st,int n);
int main(void)
{
struct namect person;
getinfo(&person);
makeinfo(&person);
showinfo(&person);
getchar();
return 0;
}
void getinfo(struct namect * pst)
{
printf("Please enter your first name.
");
s_gets(pst->fname,NLEN);
printf("Please enter your last name.
");
s_gets(pst->lname,NLEN);
}
void makeinfo(struct namect * pst)
{
pst->letters=strlen(pst->fname)+strlen(pst->lname);
}
void showinfo(struct namect * pst)
{
printf("%s %s,your name contains %d letters.
",
pst->fname,pst->lname,pst->letters);
}
char *s_gets(char *st ,int n)
{
char * ret_val;
char * find;
ret_val=fgets(st,n,stdin);
if(ret_val)
{
find=strchr(st,
);
if(find)
*find= ;
else
while(getchar()!=
)
continue;
}
return ret_val;
}
/運行結果如下(The results are as follows):/
推薦閱讀:
※如何在命令行中整理數據
※守護進程
※Spring Cloud雲架構 - commonservice-sso服務搭建
※一文看懂AI晶元競爭五大維度