我试图在struct对象中存储一些值,并且我想重复提示,直到用户输入“yes”。我想为此使用一个do-while循环。我已经失败了第一个“姓氏”的读入。当我输入某些内容时,程序停止(没有错误)。我甚至没有使用do-while,因为我不确定它是否能用于我的while()条件。
使用c和do-while循环在结构对象中存储值
#include <ctype.h>
#include <stdio.h>
#include <string.h>
struct employeelist
{
char last[6];
char first[6];
int pnumber;
int salary;
};
int main()
{
struct employeelist employee[5];
char check;
//do
//{
printf("Hello. Please type in the last name, the first name, the personal number and the salary of your employees.\n");
printf("Last name: ");
scanf("%c", employee[1].last);
printf("First name: ");
scanf("%c", employee[1].first);
printf("Personal number: ");
scanf("%d", &employee[1].pnumber);
printf("Salary: ");
scanf("%d", &employee[1].salary);
printf("You have more employess (yes/no)?: ");
scanf("%c", &check);
//}while (scanf("yes"));
return 0;
}
你确实意识到你实际上没有提出问题,对吧?你遗弃了一堆代码,并说,“它不工作”。 – abelenky 2010-11-19 19:37:56
对不起,我会在下次尝试更具体。这不是我为学校做的功课,我只是为自己学习。 – Ordo 2010-11-19 19:43:50