Results 1 to 9 of 9
  1. #1

    Default Problem with files in Turbo C


    Ei Bros, I really need your help. There's this program I've been trying to figure out for 2 days but bisag unsaon, I really can't solve it.

    Program 1 Specification:
    The program will read any file of student records whose file name is inputted by the user. Each student record contains the following fields:
    1) ID – unsigned long
    2) Name – structure containing the following fields
    a. Lastname – 16 characters
    b. Firstname – 24 characters
    c. Middle Initial – 1 character
    3) Course – 8 characters
    4) Year – integer

    The program displays the student records read from the file:
    using the following format:
    Record No. ID Lastname Firstname MI Course Year
    1 111111 Dela Cruz Juan A. BSIT 2
    2 3456746 Tan Carole Jane F. BSCS 3
    20 records are displayed at a time, i.e. the first 20 records are displayed, then the next 20 , and so on.

    The program will contain at least 2 functions:
    DisplayHeader – this will display the following header :
    Record No. ID Lastname Firstname MI Course Year
    DisplayRecord – this function will accept as parameter a single student record and displays on all screen all data in the record in 1 row.

    To check if the program will execute correctly, 3 sample files are given:
    file1.dat
    file2.dat
    file3.dat

    Program 2 Specification:
    The program will create a file of N student records whose name and number of records N are to be inputted by the user.
    Each student record will contain fields which are the same as program 1.
    The program should contain at least 2 functions:
    GetRecord – will allow user to input from the keyboard all information in a single record and return it to the calling function.
    DisplayRecord – this function will accept as parameter a single student record and displays on all screen all data in the record in 1 row. This function will be used to check if all data are correct before writing to the file.
    Use Program 1 to check if Program 2 is correct.


    My problem jud is the "fread" syntax.

    Any help would be gladly appreciated. Thanks...

  2. #2

    Default Re: Problem with files in Turbo C

    hello bro first of all gi onsa man pag write ang file?.
    pag write niya gi struct pag write?. or gi tagsa tagsa og sud ang mga values?.

    ambot lang kong sakto ni kai dugay nako wa ka gunit C/C++ ikaw nalang debug pro pari parihas rana sila ehehe.
    Code:
    typedef struct datdata
    {
     ulong id;
     namedata studentnameinfo;
     char course[8];
     int year;
    }datdata;
    
    struct namedata
    {
     char lastname[16];
     char firstname[24];
     char middle_initial[1];
    }namedata;
    
    
    datdata student1;
    FILE *fp;
    fp = fopen("mydata.dat","r");
    int inumread;
    if(fp!=null)
    {
    	inumread = fread(&student1 , sizeof(datdata),1,fp);
    	fclose(fp);
    }
    
    
    
    or
    
    if(fp!=null)
    {
    	inumread = fread(&student1.id,sizeof(student1.id),1,fp);
    	//...read all data accordingly one by one.
    }

  3. #3

    Default Re: Problem with files in Turbo C

    bro under ka ni mam peña sa USC?? hehehe! make sure lang di ni makit-an niya sa net... hehehe! mag search2x sad baya na ug forums... hehehe!

  4. #4

    Default Re: Problem with files in Turbo C

    Mam peña jud bro... hehe... Ni strikta jud cya ug samot...

  5. #5

    Default Re: Problem with files in Turbo C

    Quote Originally Posted by silent-kill
    hello bro first of all gi onsa man pag write ang file?.
    pag write niya gi struct pag write?. or gi tagsa tagsa og sud ang mga values?.
    gi struct pag write bro. And thanks kaayo by the way....

  6. #6

    Default Re: Problem with files in Turbo C

    Bro, na read na nako ang sud sa file1 but nag lisod lang ko unsaon pag store sa bag-o nga ARRAY para ako ma display..

  7. #7

    Default Re: Problem with files in Turbo C

    i dont know kong ang borland C karon naa bana siya resizable array hehehe.

    pero kong wala..

    himo ka LinkList para dynamic imong array..


  8. #8

    Default Re: Problem with files in Turbo C

    You can just use a pointer to the structure and just read the file one line at a time, then just check if you got the correct id then display.

  9. #9

    Default Re: Problem with files in Turbo C

    bai, i loop diay nimo ang fread... taysa ako sa to pangitaon ako project sauna... hehehe! pila na man intawn ni ka generations ning project-ka.. hehehe!

  10.    Advertisement

Similar Threads

 
  1. having problems with in-laws? tapok ta dri
    By baby_gabby in forum Family Matters
    Replies: 93
    Last Post: 11-30-2015, 11:52 PM
  2. Problem with the future mother-in-law !
    By mango in forum "Love is..."
    Replies: 15
    Last Post: 08-09-2011, 04:14 PM
  3. Replies: 14
    Last Post: 07-08-2009, 10:36 AM
  4. Replies: 5
    Last Post: 06-18-2008, 06:15 AM
  5. Replies: 16
    Last Post: 02-11-2008, 11:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top