Thread: fgets problem

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    99

    Exclamation fgets problem

    hey i was told to use fgets instead of scanf to read in strings that are separated by whitespace characters but the way i have it here is wrong. the error says "request for member 'name' in something not a structure or a union". any tips on how to make it correct? cheers. THE ERROR IS ON LINE 43.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    struct bones
    {
        char name[20];
        int played;
        int won;
        int drawn;
        int lost;
        int points;
    
    
    };
    
    
    
    
    struct bones team[4];
    
    
    
    
    int main()
    {
        int i;
    
    
        for(i=0;i<4;i++)
        {
            team[i].played = 0;
            team[i].won = 0;
            team[i].lost = 0;
            team[i].drawn = 0;
            team[i].points = 0;
        }
    
    
        for(i=0;i<4;i++)
        {
            printf("enter each team name\n");
            fgets(team.name[i], 20, stdin);
        }
    return(0);
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    This actually has nothing to do with fgets(). You are not properly accessing the structure member. You have an array of team, not a single team try:
    Code:
    fgets(team[i].name, 20, stdin);
    Jim

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    99
    oh my god thanks tim i feel like an idiot now haha thats it of course ha cheers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fgets problem
    By ncode in forum C Programming
    Replies: 10
    Last Post: 03-02-2012, 10:39 PM
  2. fgets() Problem
    By kihina in forum C Programming
    Replies: 3
    Last Post: 02-08-2010, 11:03 AM
  3. problem with fgets
    By learninC in forum C Programming
    Replies: 3
    Last Post: 05-19-2005, 08:10 AM
  4. problem with fgets
    By Smoot in forum C Programming
    Replies: 4
    Last Post: 12-07-2003, 03:35 AM
  5. fgets problem
    By gambitmj in forum C Programming
    Replies: 5
    Last Post: 02-26-2002, 08:55 AM