满意答案
andrew_512
2014.01.01
采纳率:48% 等级:7
已帮助:211人
亲自测试
#include
#include
#include
struct wk_long
{
char name[30];
char sex[10];
unsigned int nId;
unsigned int nAge;
};
struct wk_s
{
char name[30];
unsigned int nAge;
};
int Readin(wk_long workerS[], int nLength)
{
for (int i = 0; i < nLength; ++i)
{
printf("Please input the %d worker Information:\n", i+1);
printf("Please input the Nmae:");
scanf("%s", workerS[i].name);
printf("Please input the Sex:");
scanf("%s",workerS[i].sex);
printf("please input the ID:");
scanf("%d", &workerS[i].nId);
printf("please input the nAge:");
scanf("%d",&workerS[i].nAge);
}
return 0;
}
int Display(wk_long* pWorker)
{
printf("Name: %s\n", pWorker->name);
printf("Sex: %s\n", pWorker->sex);
printf("Id: %-5d\n", pWorker->nId);
printf("Age: %d\n", pWorker->nAge);
return 0;
}
int select(wk_long* pWorkers, wk_s* pWks, int nLen)
{
for (int i = 0; i < nLen; ++i)
{
strcpy(pWks[i].name,pWorkers[i].name);
pWks[i].nAge = pWorkers[i].nAge;
}
return 0;
}
int delwk(wk_s* pWks, wk_long* pWorkers, int nInd)
{
if (pWks[nInd].name[0] == 0)
{
printf("The people of the index is not in the simple list\n");
return 0;
}
memset(&pWks[nInd], 0, sizeof(wk_s));
memset(&pWorkers[nInd], 0, sizeof(wk_long));
printf("The Information about the index of the list is deleted\n");
}
int DisplayHelp(void)
{
printf("1. 输入数据\n");
printf("2. 显示原始数据\n");
printf("3. 制作简明数据\n");
printf("4. 删除简明数据\n");
printf("5. Goodbye!\n");
printf("Input 1-5:\n");
return 0;
}
int main()
{
wk_long workers[10];
memset(workers,0,sizeof(workers));
wk_s wkShort[10];
memset(wkShort, 0, sizeof(wkShort));
int nInput;
int nInd;
while (1)
{
DisplayHelp();
scanf("%d", &nInput);
switch(nInput)
{
case 1:
Readin(workers, 10);
break;
case 2:
for (int i = 0; i < 10; ++i)
{
if(workers[i].name[0] != '\0')
{
printf("The information of the %d number in the List:\n", i+1);
Display(&workers[i]);
}
}
break;
case 3:
select(workers, wkShort, 10);
break;
case 4:
printf("Please Input The delete index:");
scanf("%d", &nInd);
delwk(wkShort, workers, nInd);
break;
case 5:
return 0;
break;
default:
break;
}
}
return 0;
}
00分享举报