TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   Problem with variable input in C program (http://forums.techarena.in/software-development/1180105.htm)

Zool 14-05-2009 09:38 PM

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?

Katty 14-05-2009 09:40 PM

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);


Walby 14-05-2009 09:43 PM

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.


All times are GMT +5.5. The time now is 11:16 AM.