gpt4 book ai didi

c - 如何显示数组

转载 作者:太空宇宙 更新时间:2023-11-04 06:43:17 24 4
gpt4 key购买 nike

我有这个:

int i, j, w;
char *array[50];

int main ()
{
array[1]= "Perro";
array[2]= "Gato";
array[3]= "Tortuga";
array[4]= "Girafa";
array[5]= "Canario";
array[6]= "Rata";
array[7]= "Leon";
array[8]= "Tigre";
array[9]= "Rinoceronte";
array[10]= "Mosquito";
for (i=1; i<11; i++)
{

printf("El elemento %i es %s \n", i, array[i]);
}
printf("Escoja el elemento deseado");
scanf("%i", &w);

int c;
scanf("%i",&c);
return i;
}

现在我想要这样的东西:printf("Desired Element %c, array[w]); 但它失败了,为什么?

最佳答案

printf("Desired Element %c", array[w]); 

将尝试打印一个字符 (%c),但它会失败,因为数组[w] 包含一个字符串。

尝试使用 %s 代替:

printf("Desired Element %s", array[w]); 

关于c - 如何显示数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4992196/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com