As Kyuubi specified, you will want to use fprintf
instead of fputs
it will cut down on the amount of code needed. The fprintf
will write your data to a file pursuant to a format string. Since your data will be string data, you will write it out in pieces specifying %s in the format string for each piece. Take for example your ABC DEF
words. You can use fprintf
to write the string literals as follows:
fprintf (fp, " %s %s\n", "ABC", "DEF");
You can also specify the minimum field width for each word you write by specifying and integer between %
and s
, such as %10s
to write '-------ABC' out with a minimum width of 10 characters. You can also place a -
sign before the number to left align the string. For example %-10s
to output 'ABC-------'. (the dashes are really spaces, just for illustration) The can help you separate the information you want into table form without writing out a varying number of spaces for each different fprintf call.
See 'man 3 fprintf` for all the options. There are literally 1000s of examples on the web to help.