第十四话。

来源:互联网 发布:软件研发流程图 编辑:程序博客网 时间:2024/05/01 09:50

酸奶就算了吧,我更想喝酸梅汤或西瓜汁。再见

先写个简单的结构体吧,{姓名,成绩}两个数据成员

#include "stdio.h"#define n 3struct student {char name[20];int score;}main(){    struct student chengji[n];    int i;    for(i=0;i<n;i++)   {    printf("please enter an name:");        gets(chengji[i].name);        printf("please enter the score:");        gets(chengji[i].score);        }    for(i=0;i<n;i++)   {    printf("%s   ",chengji[i].name);        printf("%d\n",chengji[i].score);}}

结构体的指针

#include "stdio.h"#define n 3struct student {char name[20];int score;}main(){    struct student chengji[n];    int i;    for(i=0;i<n;i++)   {    printf("please enter an name:");        gets(chengji[i].name);        printf("please enter the score:");        gets(chengji[i].score);        }    for(i=0;i<n;i++)   {    printf("%s   ",chengji[i].name);        printf("%d\n",chengji[i].score);   }    struct student *pi;    pi =&chengji[0];    printf("the name is %s,the score is %d",pi->name,(*pi).score);}


0 0
原创粉丝点击