Thread: write to .txt file in columns

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    32

    write to .txt file in columns

    How could I write to a text file so that it appears in column format? This is for a .log file.

    It should look something like this:

    Code:
    <date>		<address>	<file>
    021125		11.34.56.156	/thisdir/thisfile
    021126		5.12.15.12	/thatdir/thatfile
    ....
    Is there a function for this or do I need to write one?

    Thanks in advance,

    Seron

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Yes there is a function: fprintf (read the - (negative) flag)
    Last edited by Monster; 11-25-2002 at 10:22 AM.

  3. #3
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807

    I think you can do something like that:

    fprintf(fp,"%s\t%d\t%d\n",nm,level,points);
    This is an example

    I think, this should work.

  4. #4
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    A tab doesn't always work.

    What about a normal fprintf with - (negative flag)?

    Code:
    printf("[%-20s] [%-20s] [%-20s]\n", "aaa", "aaaaaa", "a");
    printf("[%-20s] [%-20s] [%-20s]\n", "bbbbbbbbbb", "b", "bbbbb");
    Output:
    Code:
    [aaa                 ] [aaaaaa              ] [a                   ]
    [bbbbbbbbbb          ] [b                   ] [bbbbb               ]

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    32
    many thanks to you all

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM