using arrays withs tructures

This is a discussion on using arrays withs tructures within the C Programming forums, part of the General Programming Boards category; -Write a program that has a structure called football, contaiing address, age, id and name and enter an array of ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    2

    using arrays withs tructures

    -Write a program that has a structure called football, contaiing address, age, id and name and enter an array of 22 player to it, then print it out on the screen

    Can anyone help in this plz? it always ask for lvalue!! if anyone can write me the source i will be much grateful

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    2

    Post the code

    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    void main(void)
    {
    int i;
    char str[30];
    clrscr();
    struct football
    {
    int number;
    char  name[30];
    float age;
    char address[20];
    } team[4];
    for (i=0;i<4;i++)
    {
    scanf("%d", &team[i].number);
    gets(str);
    team[i].name=atoi(str);
    scanf("%f", &team[i].age);
    gets(str);
    team[i].address=atoi(str);
    }
    for(i=0;i<4;i++)
    {
    printf("%d", team[i].number);
    printf("%s", team[i].name);
    printf("%f", team[i].age);
    printf("%s", team[i].address);
    
    }
    getch();
    }
    &#91;code]&#91;/code]tagged by Salem

  3. #3
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511

    Red face

    Usually you define structs before main- but you can do this in main. Also, I prefer declaring struct variables with the structure definition. To me, it makes the code more organized.
    Mr. C: Author and Instructor

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  2. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  3. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  4. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM
  5. sorting arrays
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 10-13-2001, 06:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21