![]() |
| ||
| Creating a table in c I wanted to create a simple table by printing lines in between my values with a header at the top and my numbers left justified. However, when I get to a ten digit number or larger, my code seems to break and my count variable goes to zero as far as I can tell, causing a bunch of space to be printed where it doesn't need to be. I was wondering what I'm doing wrong. Thank you for any help you can offer!
|
| ||
| Re: Creating a table in c You want to print a table with the powers of 2 and you want your integers to be signed and unsigned. You're making it to complicated I think, use \t to separate your output. Or use something like printf("|%d |%u |",x,y); |
| ||
| Re: Creating a table in c The upper limit of an int is 2147483647(32-bit system). When x reaches the value 1073741824, x<<1;multiples that value by 2 which yields 2147483648 which is beyond the upper limit, hence the value goes in a circle and the number -2147483648 gets stored in x and consequently in m. since you've given while(m>0)count never gets incremented and stays at zero. It would be better to stop your table when m becomes negative. |
| All times are GMT -4. The time now is 3:00 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC