Re: long veriable causes problem
From: Robert W Hand (rwhand_at_NOSPAMoperamail.com)
Date: 04/30/04
- Next message: jeffc: "Re: Newbie OOP question"
- Previous message: Ulrich Eckhardt: "Re: temporary file in C++"
- In reply to: Ronen Kfir: "long veriable causes problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 30 Apr 2004 14:23:56 -0400
On 30 Apr 2004 01:01:27 -0700, ronenk@tauex.tau.ac.il (Ronen Kfir)
wrote:
>The following code works only with int veriable defenitions. with long
>I get wrong results, -1 does not terminate program & negative numbers
>give back odd numbers.
>
>please help.
ok, please see below.
>long number;
>void main()
main returns an int.
>{
>puts ("\nPlease enter a positive integer");
>scanf ("%d",&number); //first number input//
I assume that this line is the problem line. The conversion specifier
"%d" is for int. Yet you are passing the pointer to a long. You
should use "%ld". If the width of long and int are different, it is
more than likely that the results of the above line will be bizarre.
I would also work on your indentations. Your code is a little
difficult to read. :-)
Best wishes,
Bob
- Next message: jeffc: "Re: Newbie OOP question"
- Previous message: Ulrich Eckhardt: "Re: temporary file in C++"
- In reply to: Ronen Kfir: "long veriable causes problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|