如何消除错误“赋值中不兼容的类型”第17行 [英] how to eliminate error "incompatible types in assignment" line 17
本文介绍了如何消除错误“赋值中不兼容的类型”第17行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
/ * 该程序的目的是拆分e中的内容我]并将它们添加到数组名称,姓氏和分数。 * /
int main()
{
int 条目,i,选项;
printf( \ n请指出您要输入的记录数:\ n跨度>);
scanf( %d,& entry);
char ent [entry] [ 100 ],name [entry] [ 20 ],姓[entry] [ 20 ],得分[entry] [ 10 跨度>];
printf( \ n请输入学生的记录(在每条记录后输入一个新行),如下格式名字姓氏得分\ n);
for (i = 0 ; i< entry + 1; i ++)
{
得到(ent [i]);
printf( %s,ent [i]);
}
for (i = 0 ; i< entry +1; i ++)
{
name [i] = strtok(ent [i], ); < - 错误
printf( \ n%s \ n,名称[一世]);
}
printf( \ n请选择合适的选项:< /跨度>);
printf( \ n打印记录(按1)\ n按名字搜索(按2) \\ n按姓氏搜索(按3)\ n按分数排序(按4)\ n按姓氏排序(按5)\ n退出程序(按0)\ n);
scanf( %d,& option);
return 0 ;
}
解决方案
// 您的for循环显示不正确
// 数组基于零,因此范围为0至entry-1
for (i = 0 ; i< entry; > {
得到(ent [i]);
printf( %s,ent [i]);
}
for (i = 0 ; i< entry; > {
name [i] = strtok(ent [i], );
printf( \ n%s \ n,name [i]);
}
/* The aim of the program is to split the contents in e[i] and add them to the arrays name , surname and score. */ int main() { int entry,i,option; printf("\nPlease indicate the number of records you want to enter :\n"); scanf("%d",&entry); char ent[entry][100],name[entry][20],surname[entry][20],score[entry][10]; printf("\nPlease input records of students (enter a new line after each record), with following format first name last name score \n"); for (i=0; i<entry+1; i++) { gets(ent[i]); printf("%s",ent[i]); } for(i=0; i<entry+1; i++) { name[i] = strtok(ent[i]," "); <- Error printf("\n%s\n",name[i]); } printf("\nPlease choose the appropriate options :"); printf("\nPrint records (press 1)\nSearch by first name (press 2)\nSearch by last name (press 3)\nSort by score (press 4)\nSort by last name (press 5)\nExit the program (press 0)\n"); scanf("%d",&option); return 0; }解决方案//Your for loops appear to be incorrect //Arrays are zero based, so the range is 0 to entry-1 for (i=0; i<entry;> { gets(ent[i]); printf("%s",ent[i]); } for(i=0; i<entry;> { name[i] = strtok(ent[i]," "); printf("\n%s\n",name[i]); }
这篇关于如何消除错误“赋值中不兼容的类型”第17行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文