There is also a %n modifier that can help in certain circumstances. It returns the column on which the row has been so far. Example: you want to write several rows that are within the width of the first row, such as a table.
int width1, width2; int values[6][2]; printf("|%s%n|%s%n|\n", header1, &width1, header2, &width2); for(i=0; i<6; i++) printf("|%*d|%*d|\n", width1, values[i][0], width2, values[i][1]);
will print 2 columns of the same width of any length, which can have two rows header1 and header2 . I don't know if all implementations have %n , but Solaris and Linux do.
Patrick SchlΓΌter Nov 28 '09 at 19:31 2009-11-28 19:31
source share