char 类型的数据输入时的验证问题
定义结构体如下:typedef struct student
{
int num;
char name[20];
int age;
float score[2];
}student;
typedef struct studentNode
{
student data;
studentNode* next;
}studentNode;
source如下:
void createList(studentNode *&head)
{
int n, i = 1;
studentNode* q;
head = (studentNode*)malloc(sizeof(studentNode));
head->next = NULL;
studentNode* pnode = head;
cout << "input the amount of the students: ";
cin >> n;
while (i <= n)
{
q = (studentNode*)malloc(sizeof(studentNode));
pnode->next = q;
pnode = q;
cout << "input the " << i << "th student's information: " << endl;
cout << "name: ";
cin >> q->data.name; i++;
}
q->next = NULL;
}
我是想在标下划线的地方输入name时,对他进行数据验证,要求只能由26个英文字母、下划线和数字组成,具体怎么个验证法不知道。请指教。