If you want to end your output without an ending \n
then don't print it at the end of each line. You can print it at the beginning (well, this will make your output with one empty line always at the beginning) or better, Between the lines. E.G:
char *sep = "";
while(whatever_you_like_to_test_to_continue_the_test) {
/* the separator has been initialized to the empty string, so it will
* print nothing the first time. */
printf("%s", sep);
/* now we change it, to whatever we like to use */
sep = "\n";
/* print the body of what you want to print */
printf("....", ...);
}
/* when you reach here, the last part you wrote was the body, not the separator */
For example, in your sample code, you can decorate the elements of your matrix with a pair of brackets for each row, a return line and put everything in another pair of brackets, like this:
#include <stdio.h>
int main() {
int rows = 10, i, cols = 6, j, number = 0;
char *sep1 = "{";
for (i = 0; i < rows; ++i) {
printf("%s", sep1);
sep1 = ",\n ";
char *sep2 = "{";
for (j = 0; j < cols; ++j) {
printf("%s", sep2);
sep2 = ",";
printf("%3d", number++);
}
/* this ends the row */
printf("}");
}
printf("}"); /* the last bracket, and no newline */
} /* main */
will produce:
$ ./a.out
{{ 0, 1, 2, 3, 4, 5},
{ 6, 7, 8, 9, 10, 11},
{ 12, 13, 14, 15, 16, 17},
{ 18, 19, 20, 21, 22, 23},
{ 24, 25, 26, 27, 28, 29},
{ 30, 31, 32, 33, 34, 35},
{ 36, 37, 38, 39, 40, 41},
{ 42, 43, 44, 45, 46, 47},
{ 48, 49, 50, 51, 52, 53},
{ 54, 55, 56, 57, 58, 59}}$ _