Thread: Struct, fopen.

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    7

    Struct, fopen.

    okay i have this code.

    int round;
    char day[3];
    char time[5];
    char hometeam[3];
    char guestteam[3];
    inthometeamscore;
    int guestteamscore;

    int main(void){
    FILE *fp;

    fp=fopen("results.txt","r");


    while(!feof(fp)){
    fscanf(fp,"%d %s %s %s - %s %d - %d", &round, day, time, hometeam, guestteam, &hometeamscore, &guestteamscore);

    printf("\n%d %s %s %s - %s %d - %d", round, day, time, hometeam, guestteam,
    hometeamscore, guestteamscore);
    }
    }
    return 0;
    }

    I want to take one variable for instance day and put it into an struct containing an array.But i don't know how to use fopen in a struct. But any kind of hints on making this is apreciated
    Last edited by Dizzy++; 12-09-2010 at 03:32 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    There's a rash of people not reading the intro threads, and not using code tags.
    Read the intro, then edit your post.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Using a struct to store your data has nothing to do with fopen.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  2. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 02:24 PM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. Concatenating in linked list
    By drater in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 11:10 PM
  5. Function validation.
    By Fhl in forum C Programming
    Replies: 10
    Last Post: 02-22-2006, 08:18 AM

Tags for this Thread