我尝试使用,
if(isalpha(card[i].name))
...
但它说我不能将它与 char 类型一起使用这是我的代码: 这是结构:
struct firm {
unsigned egn;
char name[80];
char lastname[80];
char department[80];
unsigned salary;
}card[100];
这是我要检查是否只有字母然后继续的功能:
void enter()
{
int i, n;
char temp[80];
do{
cout<<"Enter how many workers you want to add: ";cin>>n;
}while(!(n>0 && n<101));
for(i=top;i<n;i++)
{/*ЕГН + проверка*/
cout<<"Enter EGN: ";do{
cin>>temp;
if((strlen(temp)!=10))
cout<<"Enter EGN: ";
}while(strlen(temp)!=10);
card[i].egn = (unsigned) atoi (temp);
/*Име Фамилия*/
cout<<"Enter name(only letters): ";cin>>card[i].name;
cout<<"Enter lastname(only letters): ";cin>>card[i].lastname;
cout<<"Enter department: ";cin>>card[i].department;
cout<<"Enter salary: ";cin>>temp;
card[i].salary = (unsigned) atoi (temp);
}
}
当我尝试使用这种代码时:
cout<<"Enter name(only letters): ";do{
cin>>card[i].name;
if(isalpha(card[i].name))
.....;
它说我不能在 int 中使用 char (isalpha 使用 int?)