How to get proper alignment when printing to file
- by user1067334
I have this Structure the elements of which that I need to write in a text file
struct Stage3ADisplay
{
int nSlot;
char *Item;
char *Type;
int nIndex;
unsigned char attributesMD[17]; //the last character is \0
unsigned char contentsMD[17]; //only for regular files - //the last character is \0
};
buffer = malloc(sizeof(Stage3ADisplayVar[nIterator]->nSlot) + sizeof(Stage3ADisplayVar[nIterator]->Item) + sizeof(Stage3ADisplayVar[nIterator]->Type) + sizeof(Stage3ADisplayVar[nIterator]->nIndex) + sizeof(Stage3ADisplayVar[nIterator]->attributesMD) + sizeof(Stage3ADisplayVar[nIterator]->contentsMD) + 1);
sprintf (buffer,"%d %s %s %d %x %x",Stage3ADisplayVar[nIterator]->nSlot, Stage3ADisplayVar[nIterator]->Item,Stage3ADisplayVar[nIterator]->Type,Stage3ADisplayVar[nIterator]->nIndex,Stage3ADisplayVar[nIterator]->attributesMD,Stage3ADisplayVar[nIterator]->contentsMD);
How do I make sure the rows in the file are properly aligned.
Thank you.