How to get proper alignment when printing to file
        Posted  
        
            by 
                user1067334
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user1067334
        
        
        
        Published on 2012-03-27T04:50:12Z
        Indexed on 
            2012/03/27
            5:30 UTC
        
        
        Read the original article
        Hit count: 260
        
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.
© Stack Overflow or respective owner