如何从C中未知长度的数组中打印每个元素 [英] How to print each element from array of unknown length in C

查看:251
本文介绍了如何从C中未知长度的数组中打印每个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

。我有很多这样的坐标

triangle_t teapot_model[] = {
{
.x1=5,
.y1=10,
},
{
.x1=20,
.y1=30,
},
(keeps going)

如何打印此项目中的所有项目数组不知道自己的位置?
我想要此输出:

How can I print all of the items in this array without knowing their position? I want this output:

Output:
.x1=5 y1=10
.x1=20 .y1=30


推荐答案

C中的数组

要简单地打印数组的每个元素,使用下面的代码就足够了。

To simply print each element of your array, using the below code should suffice

int sizearray = sizeof teapot_model  / sizeof *teapot_model;

for (int i = 0; i < sizearray; i++) 
{
    printf(".x1=%d .y1=%d\n", teapot_model[i].x1, teapot_model[i].y1);
}

这篇关于如何从C中未知长度的数组中打印每个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆