c – Is there a way to have printf() properly print out an array (of floats, say)?

c – Is there a way to have printf() properly print out an array (of floats, say)?

you need to iterate through the arrays elements

float foo[] = {1, 2, 3, 10};
int i;
for (i=0;i < (sizeof (foo) /sizeof (foo[0]));i++) {
    printf(%lfn,foo[i]);
}

or create a function that returns stacked sn printf and then prints it with

printf(%sn,function_that_makes_pretty_output(foo))

You have to loop through the array and printf() each element:

for(int i=0;i<10;++i) {
  printf(%.2f , foo[i]);
}

printf(n);

c – Is there a way to have printf() properly print out an array (of floats, say)?

You need to go for a loop:

for (int i = 0; i < sizeof(foo) / sizeof(float); ++i)
   printf(%f, foo[i]);
printf(n);

Leave a Reply

Your email address will not be published.