I have a file and I want to insert data in it as columns like this:
Column size: 5spaces 5spaces 12 spaces
25100 23501 169247103621
But I still have this two conditions:
- If the string bigger then the column size, I eliminate the odd
length from the string. - If the string smaller then the column size, I fill the rest of
string with spaces.
Ex1:
2510025 23501 169247103621
Become:
25100 23501 169247103621
Ex2:
25 23501 169247103621
Become:
25 23501 169247103621
I manged to get this in c with printf, but now I want print some format in a file.
#include <stdio.h>
int main(int argc, char **argv)
{
char FMT[] = "%-5.5s %5s %-6.12s\n";
FILE *hFile = NULL;
char *string = "freeifaddrss";
char *string2 = "cards";
char *string3 = "ifa_nextifa_next";
printf(FMT, string, string2, string3);
return 0;
}
To write to a file you can either redirect the output of your program, eg:
or open a file in the program and write to that:
Call this with: