结构体

#include

int search(int key,int shuzi[],int length_shuzi) { int result = -1; int control; for (control = 0;control <length_shuzi;control++) { if (key == shuzi[control]) { result = control; break; } }

return result;

}

int main(void) { //int shuzi[] = {1,2,3,}; //char *zimu[] = {"one","two","third"}; //long long length_shuzi = sizeof(shuzi)/sizeof(shuzi[0]);

struct {
    int shuzi;
    char *zimu;
} shuzu[] = {
    {1,"one"},
    {2,"two"},
    {3,"third"}
};

int key;
scanf("%d",&key);
//int result =search(key,shuzi,length_shuzi);

for (int control = 0;control < sizeof(shuzu)/sizeof(shuzu[0]);control++) {
    if (key == shuzu[control].shuzi) {
        printf("%s\n",shuzu[control].zimu);
    }
}
return 0;

}

JSRUN前端笔记, 是针对前端工程师开放的一个笔记分享平台,是前端工程师记录重点、分享经验的一个笔记本。JSRUN前端采用的 MarkDown 语法 (极客专用语法), 这里属于IT工程师。