473,395 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Printing datatypes problem

My program is just printing ranges but the unsigned integer is not working. The max is suppose to be 65535. And also integer is messed up. And also long is. I'm new to programming and books can be vague.

C:\Documents and Settings\Mikes\Desktop\Cprog>gcc Datatypes.c -o Datatypes.exe

C:\Documents and Settings\Mikes\Desktop\Cprog>Datatypes
Character min: -128

Character max: 127

Integer min: -2147483648

Integer max: 2147483647

Long min: -2147483648

Long max: -2147483648

Short min: -32768

Short max: 32767

Signed Character min: -128

Signed Character max: 127

Unsigned Character max: 255

Unsigned Integer max: 4294967295

Unsigned Long max: 4294967295

Unsigned Short max: 65535


C:\Documents and Settings\Mikes\Desktop\Cprog>
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<limits.h>
  3. #include<float.h>
  4. main()
  5. {
  6. /* A program to determine the range of data types */
  7. printf("Character min: %d\n\n", CHAR_MIN); 
  8. printf("Character max: %d\n\n", CHAR_MAX); 
  9. printf("Integer min: %d\n\n", INT_MIN); 
  10. printf("Integer max: %d\n\n", INT_MAX);
  11. printf("Long min: %d\n\n", LONG_MIN);
  12. printf("Long max: %d\n\n", INT_MIN);
  13. printf("Short min: %d\n\n", SHRT_MIN);
  14. printf("Short max: %d\n\n", SHRT_MAX);
  15. printf("Signed Character min: %d\n\n", SCHAR_MIN);
  16. printf("Signed Character max: %d\n\n", SCHAR_MAX);
  17. printf("Unsigned Character max: %d\n\n", UCHAR_MAX);
  18. printf("Unsigned Integer max: %u\n\n", UINT_MAX);
  19. printf("Unsigned Long max: %lu\n\n", ULONG_MAX);
  20. printf("Unsigned Short max: %d\n\n", USHRT_MAX);}
Aug 8 '15 #1
4 1603
weaknessforcats
9,208 Expert Mod 8TB
Some of the format specifiers you use are not correct. For example, %c is for char and %d is for signed integer. Go through your code and be sure you use the correct specifier.

Also, the size of types varies by compiler implementation. You should do a sizeof(type) to see how big the type is. Often the int and the long int are the same size.

Be sure char is signed. It's not required to be signed. The only sure signed char is: signed char. There should be compiler info or settings for this. If a char is 8 bits the max value is 255. A max value of 127 is for an 8-bit char with a 0 for the sign bit. So this applies only to signed char. A max value of 128 is binary 1000 0000. That left bit 1 is the sign bit. It's not part of the data. A 1 in the sign bit means a negative number. An unsigned 8-bit char has no sign bit so it's max positive value is 1111 1111 which is 255.

Negative values are often stored in 2's-complement format so just looking at the binary does not tell you the value. This is why the printf format specifiers are so important. They will convert to decimal so you can read the data value.
Aug 8 '15 #2
Idk their much bigger than indicated in the book, but the book is old. I went to wikipedia https://en.wikipedia.org/wiki/C_data_types to correct each one and size is not changing so that must be the size. Int is 16 to 32 bits and not necessarily the same size as long but in the case it looks like they are. Thanks for the input.
Aug 8 '15 #3
donbock
2,426 Expert 2GB
I don't see anything wrong with the values you listed in the original posting.

The C Standard allows the compiler writer to set these limits as they wish ... as long as their choices fit within the broad outline mandated in the Standard. You wouldn't expect two different compilers to report the same limit values.
Aug 8 '15 #4
The whole point of this exercise was to use to start using diffrent header files for the first time. In the book INT is +/- 32767, UINT is 65535. Which when your a beginner and you get numbers not intended you begin to think your doing something wrong. When I fixed everything, INT was still 32 bits and UINT was same size as ULONG which as you can see from the numbers. They're 16 bit in the book that's all.
Aug 8 '15 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: DT | last post by:
I am working on a windows form application which does some printing. The problem I have been having is the "printing progress" window that pops up when the page is about to print. How do I disable...
2
by: William Bradley | last post by:
I have a form on to which I have added a button that will cause only that form to be printed as a Bin Label. It works fine but it does not release when it finished printing the current record. If I...
0
by: Mo Sihra | last post by:
hi when I try to print Access reports from VB 6.0 , Access gives some security warning and instead of printing the report, it tries to save it in some .mdi format. Please help me with opening and...
0
by: Jeffrey V | last post by:
Hi! I'm trying to print to a DYMO LabelWriter 300 Turbo. I print Landscape and each time the printing starts at the middle of the label. I set all the Margins at 0 and OriginAtMargins = True...
2
by: davem | last post by:
Hi, I am writing a program in VB6 where an image is loaded into a picture box if I print this image it is exactly where I expect it to be. The problem is I need to be able to draw lines on the...
0
by: CharlesLondon | last post by:
Hi, I had a problem with printing winform in C#. In document properites setting, Effects tab, there is a Resizing Options, where users can resize the prints. This scale value is important, when...
1
by: moonman | last post by:
I'm not very good at css but from what I've read it is possible to print the content of a scrolling div. I have tried everything with no luck. From what I've found using a css for the print should...
2
daniel aristidou
by: daniel aristidou | last post by:
Hi i wrote code to print records off a datagrid.the code works on all but one of my data grids. The problem is that loop continues without stopping, Causing the program to crash. The only diff...
3
by: slenish | last post by:
Hi, I am having a problem when I go to print a report from my query. I want to print peoples names in my query that is in the names column but when i try to print them it keeps reprinting the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.