周记

这是本周学习的代码是让我们先定义一个日期结构体,结构成员包括年、月、日,然后建立通讯录结构体,结构体成员包括姓名、电话号码,之后再定义一雇员结构体,结构体成员包括:雇员姓名、职称、出生日期,通讯录(3个),最后输出。代码如下:

#include "stdafx.h"
#include "string.h"
#include "stdlib.h"
void OutPut(struct empl *ps, int n);
struct Date{
int year;
int month;
int day;
};
struct TongXunLu{
char name[20];
int tel;
};
struct empl{
char name[20];
char job[20];
struct Date bday;
struct TongXunLu Tx[3];
};
int main(int argc, char* argv[])
{
struct empl e1 = {"xiuzhe","shangxue",1937,12,12,"erwa",1234456,"goudang",12345,"tiezhu",345123};
OutPut(&e1,1);
empl e2;

strcpy(e2.name,"Peter");strcpy(e2.job,"shangke");
e2.bday.year=1945;e2.bday.month=11;e2.bday.day=23;
strcpy(e2.Tx[0].name,"enen"); e2.Tx[0].tel=1324456;
strcpy(e2.Tx[1].name,"cheng"); e2.Tx[1].tel=15679456;
strcpy(e2.Tx[2].name,"chengyi"); e2.Tx[2].tel=15679456;
OutPut(&e2,1);

struct empl e[2]={{"Mary","English",1985,4,17,},{2345,"Mike","English",66,"C",79}};
OutPut(ss,2);
struct student *pstu;
pstu=(student *)malloc(sizeof(student));
strcpy(pstu->name,"Jone");pstu->num=999;
strcpy( pstu->sco[0].course,"English"); pstu->sco[0].grade=66;
strcpy( pstu->sco[1].course,"Java"); pstu->sco[1].grade=63;
OutPut(pstu,1);
free(pstu);
getchar();
return 0;
}
void OutPut(struct empl *ps, int n){
int i,j;
for(i=0;i<n;i++){
printf("姓名=%s 工作=%s \n",ps->name,ps->job);
printf("出生年月=%d-%d-%d\n",ps->bday.year,ps->bday.month,ps->bday.day);
for (j=0;j<3;j++)
{
printf("姓名=%s,电话=%d \n",ps->Tx[j].name,ps->Tx[j].tel);
}
printf("\n\n");
ps++;
}
}

posted @ 2016-04-07 19:38  fjsnww  阅读(127)  评论(2编辑  收藏  举报