/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */
#include
struct btbucode//定义结构体btbucode
{
int n;
char pn[50];
};
struct btbucode code[]={{11, "cailiao"},{12, "caiji"},{13, "shang"},{14, "jingji"},{15, "jixin"},
{16, "shipin"},{17, "lixueyuan"},{18, "fama"},{19, "waiguoyu"},{20, "yishuchuanmei"},
{95, "gonghui"},{96,"jiaowuchu"},{97,"renshichu"},{98,"kejichu"},{99,"xiaoban"}};//定义结构体数组code并初始化
/* PRESET CODE END - NEVER TOUCH CODE ABOVE */
#include
int main()
{int m,flag=0,i;
scanf("%d",&m);
for(i=0;i<strlen(code);i++)
if(m==code[i].n) {flag=1;printf("%s\n",code[i].pn);break;}
if(flag==0) printf("未找到\n");
return 0;}
我用了一个strlen函数来算结构体数组长度 但是出现错误提示
error C2664: 'strlen' : cannot convert parameter 1 from 'struct btbucode [15]' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast