|
From: <jp...@bo...> - 2002-06-07 01:23:31
|
Rob, I didn't got any error message when I tried to compile and
run your program. By the way, I'm working with an Athlon
800MHz/WinXP/DevCpp 4.9.3.0.
Juliano
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of rchavez
Sent: quinta-feira, 6 de junho de 2002 19:08
To: dev...@li...
Subject: [Dev-C++] short integer problem
Hi,
While trying a problem from my text 'A Book on C' I ran into some
strange behavior for short integers. If I use integers, the program
below reads them in & performs the arithmetic correctly. But if I
change line 3 so the variables are of type short, the value of x is
always 0 !!
I've played with it a lot but can't find the problem. Any help would be
appreciated. Also, notice that the scanf for var ss at the bottom
always works. It's not a gcc bug since I get the same behavior on a
unix compiler.
Rob
/** Math on Short Integers **/
main()
{
short x,y, entries=2; /* declared as int program works as
expected */
short ss;
printf("\n sizeof(short): %d",sizeof(short));
printf("\n2 to the 15: %d\n\n",128*128*2);
printf("\n Enter 2 int values: \n");
entries=scanf("%d",&x);
entries +=scanf("%d",&y);
printf("\n x= %d y= %d",x,y);
while (entries == 2) {
printf("\n x= %d y= %d",x,y);
printf("\nX+Y = %d",x+y);
printf("\nX-Y = %d",x-y);
printf("\nX*Y = %d",x*y);
printf("\nX/Y = %d",x/y);
printf("\nx %c y = %d\n",'\045',x%y);
ss = 64000;
printf("\nEnter a short int");
scanf("%d",&ss);
printf("\n Another try on a short int gives: %d",ss);
printf("\n Enter 2 int values: ");
entries=scanf("%d%d",&x,&y);
}
printf("\n\n");
system("PAUSE");
return 0;
}
_______________________________________________________________
Don't miss the 2002 Sprint PCS Application Developer's Conference August
25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|