Thread: whats the best arrangement in writing to a FILE?

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    39

    whats the best arrangement in writing to a FILE?

    what's the best arrangement when i intend to write my array of structs to a file?
    my array of structs is like this....

    Code:
    typedef struct student_profile{
    	long long int stud_num;
    	char name[50];
    	char bday[50];
    	char course[50];
    	} STUDENT;
    
    STUDENT array[20];
    because later, ill write the informations in the array of structs to a FILE for saving information...

    others say like writing like this in the FILE...

    student number0 name0 bday0 course0
    student number1 name1 bday1 course1
    etc....

    where each student account will occupy one line, and infos will be separated by tabs...
    is this the best arrangement?

    thanks!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you define a comprehensive criteria for "best", I will tell you what is best.

    If "best" is "easiest", then I would say something along those lines is a good plan. I would perhaps even go as far as doing:
    Code:
    studentNumber0
    Name0
    BDay0
    ...
    Makes it very easy to read in a line of data for each struct element. If you have them all on a line, it gets more interesting with regards to separating a line into elements.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 10:47 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM