下面代码执行后要输入姓名和年龄,年龄是整型。如果输入是字符型时会出错!
怎么改 能在输入年龄类型错误后会提示出<输入类型错误!> 再需要重新输入!
帮忙下!
#include <malloc.h>
#include <stdio.h>
#define List_Max_Size 100
#define Add_Size 10
struct Human_Data {
char Name [20];
int Age;
};//定义顺序表数据结构体
typedef Human_Data Thread_Save_Struct;
struct Thread_1 {
int Length;
int List_Size;
Thread_Save_Struct *Point;
};//定义顺序表指针结构体
typedef Thread_1 Thread;
int Create_List( Thread &List )
{
List.Point = (Thread_Save_Struct * )malloc ( sizeof(Thread_Save_Struct) * List_Max_Size);
if ( !List.Point ) return (0);
List.List_Size = List_Max_Size;
List.Length = 0;
return (1);
}//建立一个顺序表
int main()
{
int Create_List( Thread &List );
int OnOff = 1;
int Add = 0;
Thread_Save_Struct *Point_1;
Thread User;
if (Create_List(User)==1)
{
printf("\n","存储空间开辟成功");
for (Point_1 = User.Point;OnOff==1 && User.Length<User.List_Size;Point_1++)
{
printf("当前指针域:%d\n",Point_1);
printf("在此输入名字:");
scanf("%s", &(Point_1->Name));
printf("在此输入年龄:");
scanf("%d", &(Point_1->Age));
// if(Point_1->Age==NULL) printf("error:输入年龄类型错误!");
printf("是否继续输入?是(1),否(0):");
scanf("%d",&OnOff);
User.Length++;
}//for
printf("当前指针域:%d\n",Point_1);
for (Point_1 = User.Point;Add != User.Length ;Point_1++)
{
printf("当前指针域%d\n",Point_1);
printf("姓名:%s\n",Point_1->Name);
printf("年龄:%d",Point_1->Age);
scanf("%d", &OnOff);
Add++;
}//for
}//if
else printf("%s\n","存储空间开辟失败");
return 0;
}//main