简体   繁体   English

在C中循环遍历没有输出的数组

[英]Looping through an Array in C with no output

Here is my code: 这是我的代码:

int main()
{
int tiles[9];
int counter=0;
int i=1;
while (counter<8)
{
    tiles[counter]=i;
    counter=counter+1;
    i=i+1;
    }
int running_total=0;
int current_number;
printf(tiles);

return 0;
}

But I get no output, what is my problem? 但是我没有输出,这是什么问题? I'm new to C so I appreciate any comments/criticism. 我是C的新手,所以感谢任何评论/批评。

Edit: I do get an output, but it's a smily face... 编辑:我确实得到了输出,但这是一个笑脸...

  1. If you want to print a number, you need a format string. 如果要打印数字,则需要格式字符串。
  2. If you want to print an array, you need to loop through it. 如果要打印数组,则需要遍历它。

     int i; for ( i = 0; i < sizeof(tiles)/ sizeof(tiles[0]); ++i) printf("%d ", tiles[i]); // << added a space for Dietrich Epp :) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM