Results 1 to 3 of 3

Thread: Problem with variable input in C program

  1. #1
    Join Date
    Apr 2009
    Posts
    87

    Problem with variable input in C program

    I have a problem with the real variable. i can put age on the console instead of 20 in the course of the variables.
    Code:
    # include <stdio.h> 
      # include <stdlib.h> 
    
      int main (int arg, char * argv []) 
      ( 
      long age = 0; 
      printf ( "How old are you?"); 
      scanf ( "% ld", & age); 
      printf ( "you really  ld% year \ n", & age); 
        system ( "PAUSE"); 
        return 0; 
      )
    could you help me to solve this problem please?

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: Problem with variable input in C program

    do not pass the address instead of the value of your variable

    Code:
     int age = 0; 
      printf (what is your age:); 
      scanf ( "% d", & age); 
      printf ( "I% d years", age);

  3. #3
    Join Date
    Jan 2009
    Posts
    199

    Re: Problem with variable input in C program

    in Line 9, we should not put the ampersand to 'age' as% printf expects a value, not an address. This is what your declaration does not boot you if your variable are not declared.

Similar Threads

  1. Replies: 4
    Last Post: 29-12-2010, 06:49 AM
  2. Windows batch file: set output of program to a variable?
    By supernoob in forum Windows Software
    Replies: 5
    Last Post: 17-10-2010, 05:58 AM
  3. How to input variable in string.find method in C++
    By Caelaan in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 10:50 PM
  4. Difficulty in input program
    By Carnie in forum Software Development
    Replies: 3
    Last Post: 04-12-2009, 01:13 PM
  5. Replies: 2
    Last Post: 28-08-2009, 07:51 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,717,388,925.68407 seconds with 16 queries