你的 printf 应该是这样的:
printf("%s type\n", a[x]);
因为你的数组元素是字符串。
更改printf
上述输出的语句后:
输出:
Tires type
Lights type
Seats type
\n
如果你喜欢,你可以删除printf
我添加的。在这种情况下,这里是输出:
Tires typeLights typeSeats type
这是我的代码:(轮胎应该显示在这个实施中)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
int x = 0;
char a[3][20];
strcpy(a[0], "Tires");
strcpy(a[1], "Lights");
strcpy(a[2], "Seats");
while(1) // i left in this while as may be using it for something that you haven't shown in your code.
{ // But if you are not using while get rid of it .. its unnecessary
for(x = 0; x< 3; x++)
{
printf("%s type\n", a[x]);
}
break;
}
return 0;
}
这是此代码的运行方式:
Notra:Desktop Sukhvir$ gcc -Werror -Wall -g -o try try.c -std=c99
Notra:Desktop Sukhvir$ ./try
Tires type
Lights type
Seats type