Reputation: 45
How can I print an array without changing line? I have this array. I want to print its element in one single line, for example (a b c d)
.
char word[20][20];
for (j = 0; j < 10; j++)
{
puts(word[j]);
}
Upvotes: 0
Views: 2305
Reputation: 40145
#include <stdio.h>
int main() {
char word[20][20] = { "a", "b", "c", "d"};
int j;
putchar('(');
for (j = 0; j < 4; j++){
if(j)
putchar(' ');
fputs(word[j], stdout);
}
puts(")");
return 0;
}
Upvotes: 1
Reputation: 106022
puts
placees a \n
after writing char
array to standard output. Use printf("%s", word[j])
instead.
Upvotes: 3