Thread: Help with struct

  1. #1
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681

    Help with struct

    Ok I know the problem is with how I am using the struct. Anyone able to smack me into the right direction?

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <stdio.h>
    
    #define MAX 2
    
    int main()
    {
    int count;
    
    struct city
           {
           int sec;
           char name[15];
           }names[MAX];
    
    
    for (count=0;count<MAX;count++)
        {
        printf("\nCity %d:\nType in sector:  ",count);
        scanf("%d",&names[count].sec);
    
        printf("Type in name:  ");
        scanf("%s",&names[count].sec);
        }
    
    for (count=0;count<MAX;count++)
        printf("City %d in Sector %d with the name of %s.\n", count, names[count].sec, names[count].name);
    
          system("PAUSE");
          return 0;
    }

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Code:
    printf("Type in name:  ");
    scanf("%s",&names[count].sec);
    See anything wrong?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Thanks, I was so certain I was messing up with the struct command I didn't even think to check and make sure I didn't make a bone head mistake like that

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-03-2008, 03:10 AM
  2. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  3. Replies: 10
    Last Post: 05-18-2006, 11:23 PM
  4. What's wrong with my search program?
    By sherwi in forum C Programming
    Replies: 5
    Last Post: 04-28-2006, 09:57 AM
  5. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM