才开始学C++ 这个关于信息录入的问题 求帮忙
代码如下#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
struct user_info
{
char name[12];
unsigned short age;
unsigned short num;
char major;
unsigned short clas;
unsigned short roomnum;
char classname;
unsigned short grade;
};
int main(int argc, char* argv[])
{
char buff[128];
struct user_info info;
FILE *fp;
int count = 0;
printf("\n%s\n\n","该程序用于把用户输入的用户信息写入record.dat文件");
fp = fopen("record.dat", "wb+");
if(fp == NULL)
{
printf("%s", "打开文件record.dat失败,程序结束");
return -1;
}
while(1)
{
memset(&info, 0, sizeof(struct user_info));
printf("%s\n","请输入一个用户的信息(直接回车结束录入):");
memset(buff, 0, 128);
printf("姓名:");
fgets(buff, 128, stdin);
if(strlen(buff) <= 1)
{
printf("%s\n", "结束输入用户信息");
break;
}
memcpy(info.name, buff, strlen(buff) - 1);
while(1)
{
memset(buff, 0, 128);
printf("年龄:");
fgets(buff, 128, stdin);
if(strlen(buff) <= 1)
{
printf("%s\n", "年龄数据不能为空,请重新输入");
}
else
{
info.age = atoi(buff);
break;
}
}
while(1)
{
memset(buff, 0, 128);
printf("学号:");
fgets(buff, 128, stdin);
if(strlen(buff) <= 1)
{
printf("%s\n", "学号数据不能为空,请重新输入");
}
else
{
info.num = atoi(buff);
break;
}
}
memset(buff, 0, 128);
printf("专业:");
fgets(buff, 128, stdin);
if(strlen(buff) <= 1)
{
printf("%s\n", "结束输入用户信息");
break;
}
while(1)
{
memset(buff, 0, 128);
printf("班级:");
fgets(buff, 128, stdin);
if(strlen(buff) <= 1)
{
printf("%s\n", "班级数据不能为空,请重新输入");
}
else
{
info.clas = atoi(buff);
break;
}
}
while(1)
{
memset(buff, 0, 128);
printf("宿舍号:");
fgets(buff, 128, stdin);
if(strlen(buff) <= 1)
{
printf("%s\n", "宿舍号数据不能为空,请重新输入");
}
else
{
info.roomnum = atoi(buff);
break;
}
}
memset(buff, 0, 128);
printf("课程:");
fgets(buff, 128, stdin);
if(strlen(buff) <= 1)
{
printf("%s\n", "结束输入用户信息");
break;
}
while(1)
{
memset(buff, 0, 128);
printf("成绩:");
fgets(buff, 128, stdin);
if(strlen(buff) <= 1)
{
printf("%s\n", "成绩数据不能为空,请重新输入");
}
else
{
info.grade = atoi(buff);
break;
}
}
printf("当前成功录入%d个用户信息\n\n", count);
fclose(fp);
printf("%s", "按任意键结束程序...");
getch();
return 0;
}
}
结果显示 当先录入0个信息 怎么修改 帮个忙啦