Print multiple integers at once

I was wondering if there is a better way to print an int array in c;

At the moment, I am doing printf("%d" ,.. )for each int in my array.

However, does this cause one system call for int? (if my understanding is correct).

It would be better to convert the int array to a string buffer and then print the buffer in one call.

I can write code for it if necessary.

Q1. is it a good idea or too much trouble to be worth it?

Q2. Are there libraries that implement such a thing. (No matter what google I get back to beginner's tutorials for printing integers: s)

Edit The size of the array is unknown before.

+5
source share
2 answers

printf, . , "" - , fflush(stdout), , \n . , .

, int , <stdio.h>, : , sprintf printf, , printf . \n, .

+3

, int, stdout . stdio: , . printf. , - :

for (i=0; i+4<=N; i+=4)
    printf("%d %d %d %d ", a[i], a[i+1], a[i+2], a[i+3]);
for (; i<N; i++)
    printf("%d ", a[i]);
+3

All Articles