Thread: Structure Problem! (Help!!)

  1. #1
    Registered User
    Join Date
    Nov 2006

    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]
    #include <stdio.h>
    #include <stdlib.h>
    /*This is where I state my structure*/
    struct cities {
      char George;
      char Tom;
      char Luke;
      char Mike;
    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");
        if (input == 1) 
            if (input == 2) 
             if (input == 3) 
            if (input ==4)
            printf("\n Mike\n",Mike);
      return 0;
    Any help would be appreciated!!!


  2. #2
    Registered User
    Join Date
    May 2006
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > 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.

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, 02:53 PM