Structure Problem! (Help!!)

This is a discussion on Structure Problem! (Help!!) within the C Programming forums, part of the General Programming Boards category; [B]I've been trying to create a system using structures, when the user presses a corresponding number, a name, and subsequently ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    4

    Unhappy Structure Problem! (Help!!)

    [B]I've been trying to create a system using structures, when the user presses a corresponding number, a name, and subsequently details can be printed..[

    But, after a few attempts..after compiling, it just 'crashes'...can anyone help me?/B]
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    /*This is where I state my structure*/
    struct cities {
      char George;
      char Tom;
      char Luke;
      char Mike;
    };
    /*Variables*/
    int (input);
    
    int main(void)
    {
        /* The input area for the user to decide*/
        printf("\nWhich city would you like to know a little something about?");
        printf("\n For George press 1\n Tom press 2\n Luke press 3\n Mike press 4\n");
        scanf("%d",input);
    
    
        if (input == 1) 
            printf("\nGeorge\n",George);
            
            if (input == 2) 
            printf("\nTom\n",Tom);
            
             if (input == 3) 
            printf("\nLuke\n",Luke);
            
            if (input ==4)
            printf("\n Mike\n",Mike);
    
      
      system("PAUSE");
      	
      return 0;
    }
    Any help would be appreciated!!!

    X

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    Really simple. You need to pass the address of 'input' to scanf() and not the object itself. Therefore, you want to have '&input' and not just 'input' in there. Besides, it is useless and more confusing than anything to surround variables with parenthesis when you are declaring variables.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    > int (input);
    I don't think these parentheses do much for you either.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem getting structure to work in my function
    By Tom Bombadil in forum C Programming
    Replies: 18
    Last Post: 05-28-2009, 09:53 AM
  2. Problem with structure and class
    By Bargi in forum C++ Programming
    Replies: 3
    Last Post: 09-25-2007, 02:30 AM
  3. Problem with arrays inside a structure
    By babu in forum C Programming
    Replies: 4
    Last Post: 07-12-2007, 09:35 AM
  4. accessing structure pointer problem
    By godhand in forum C Programming
    Replies: 2
    Last Post: 04-09-2004, 10:52 PM
  5. Problem checking for numeric value in a structure
    By ronkane in forum C++ Programming
    Replies: 4
    Last Post: 01-20-2002, 01:53 PM

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