Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 14-05-2009
Member
 
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?
Reply With Quote
  #2  
Old 14-05-2009
Member
 
Join Date: May 2008
Posts: 2,008
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);
Reply With Quote
  #3  
Old 14-05-2009
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Problem with variable input in C program"
Thread Thread Starter Forum Replies Last Post
Make a program behave on the basis of input given dring execution Karumbu Software Development 4 29-12-2010 06:49 AM
Windows batch file: set output of program to a variable? supernoob Windows Software 5 17-10-2010 05:58 AM
How to input variable in string.find method in C++ Caelaan Software Development 5 29-01-2010 10:50 PM
Difficulty in input program Carnie Software Development 3 04-12-2009 01:13 PM
Runtime Error 91 : Object Variable or with block variable not set Ryan21 Software Development 2 28-08-2009 07:51 PM


All times are GMT +5.5. The time now is 02:28 PM.