473,806 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem abt printf on Turboc

Hello all ,
I need a help on this code
kindly help me out
for the below code I worked on the Turboc
the result I was expecting was different from what has been printed I
have indicated the line with " /*this one*/" line no 10
I did expected some junk for the first %ld and 6553 for the second %d
,but it printed in different way I am also pasting the result printed ,
it is below the code .
I am totally confused because I got one answer that was it depends on
compiler but I am not satisfied .can any body kind hearted people help
me with proper explanation

thanks and regards

/*code */

1 int main(void)
2 {
3 unsigned int un = 3000000000; /* system with 32-bit int */
4 short end = 200; /* and 16-bit short */
5 unsigned int big = 6553;
6 long long verybig = 12345678908642;
7 clrscr();
8 printf("un = %u and not %d\n", un, un);
9 printf("end = %hd and %d\n", end, end);
10 printf("big = %ld and not %d\n", big,big); /*this one */
11 printf("verybig = %lld and not %ld\n", verybig, verybig);
12 getch();
13 return 0;
14 }
the Output is below

un = 24064 and not 24064
end = 200 and 200
big = 429463961 and not 996 /* <-why it is 996 whynot 6553*/
verybig= 1942899938 and not 1942899938

Nov 14 '05 #1
31 2197
mu************@ hotmail.com wrote:

Thought I'd try blending in ... ;-)
Hello all ,
I need a help on this code
kindly help me out
for the below code I worked on the Turboc
the result I was expecting was different from what has been printed I
have indicated the line with " /*this one*/" line no 10
I did expected some junk for the first %ld and 6553 for the second %d
,but it printed in different way I am also pasting the result printed ,
it is below the code .
I am totally confused because I got one answer that was it depends on
compiler but I am not satisfied .can any body kind hearted people help
me with proper explanation

thanks and regards

/*code */

1 int main(void)
2 {
3 unsigned int un = 3000000000; /* system with 32-bit int */
4 short end = 200; /* and 16-bit short */
5 unsigned int big = 6553;
6 long long verybig = 12345678908642;
<error message="OT in c.l.c" cause="Not ISO C"
redirect="borla nd.public.cpp.t urbocpp">
7 clrscr();
</error>
8 printf("un = %u and not %d\n", un, un);
9 printf("end = %hd and %d\n", end, end);
10 printf("big = %ld and not %d\n", big,big); /*this one */
11 printf("verybig = %lld and not %ld\n", verybig, verybig);
12 getch();
13 return 0;
14 }
the Output is below

un = 24064 and not 24064
end = 200 and 200
big = 429463961 and not 996 /* <-why it is 996 whynot 6553*/
verybig= 1942899938 and not 1942899938

Nov 14 '05 #2
I didnt get you
if it is any error please comment the lines "clrscr()" and "getch()"
thanks

Nov 14 '05 #3


mu************@ hotmail.com wrote:
I didnt get you
if it is any error please comment the lines "clrscr()" and "getch()"


Please ignore "Eltee". He/she/it is a newly acquired troll round here.

- Michael
--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #4


mu************@ hotmail.com wrote:
Hello all ,
I need a help on this code
kindly help me out
for the below code I worked on the Turboc
the result I was expecting was different from what has been printed I
have indicated the line with " /*this one*/" line no 10
I did expected some junk for the first %ld and 6553 for the second %d
,but it printed in different way I am also pasting the result printed ,
it is below the code .
I am totally confused because I got one answer that was it depends on
compiler but I am not satisfied .can any body kind hearted people help
me with proper explanation

thanks and regards

/*code */
0a #include <stdio.h>
1 int main(void)
2 {
3 unsigned int un = 3000000000; /* system with 32-bit int */
4 short end = 200; /* and 16-bit short */
5 unsigned int big = 6553;
6 long long verybig = 12345678908642;
7 clrscr(); 7 printf("\v\v\v" ); 8 printf("un = %u and not %d\n", un, un);
9 printf("end = %hd and %d\n", end, end);
10 printf("big = %ld and not %d\n", big,big); /*this one */
11 printf("verybig = %lld and not %ld\n", verybig, verybig);
12 getch(); 13 getchar(); 13 return 0;
14 }
the Output is below

un = 24064 and not 24064
end = 200 and 200
big = 429463961 and not 996 /* <-why it is 996 whynot 6553*/
verybig= 1942899938 and not 1942899938


Are you sure about the size of your data types?
I would rather use

0b #include <limits.h>

and initialise the variables accordingly:

3 unsigned in un = UINT_MAX - 1;
6 long long verybig = LLONG_MAX;

This is portable.

Another thing: If long int is a wider data type than int,
then the arguments of printf() are evaluated wrongly in line 10.
In addition, I would either output unsigned int or make big signed
int:

10 printf("big = %u and not %lu\n", big,big); /*this one */
As to the problems with long long:
Are you sure that your compiler is C99 compliant?
Try
0c #ifndef __STDC_VERSION_ _
0d # error Error: __STDC_VERSION_ _ not defined
0e #elif __STDC_VERSION_ _ < 199901L
0d # error Error: Not C99 compliant
0f #endif
Another thing: Maybe your standard library printf() does not
support long long.
Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #5
On 29 Dec 2004 04:48:53 -0800, in comp.lang.c , mu************@ hotmail.com
wrote:
I am totally confused because I got one answer that was it depends on
compiler but I am not satisfied .can any body kind hearted people help
me with proper explanation


You're lying to the compiler. The format string you pass to printf must
match the type of the variables passed. Otherwise the results will be
garbage. Note also that the size of short, int, long and long long depend
on the compiler and OS. so sometimes you'll get lucky, and using the wrong
specifier will 'work'.

If you want to know *exactly* why its 996 not 6553, the answer lies in the
bitpattern of how your Compiler or OS stores numbers. Thats offtopic here
and would be different on each different OS.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >
Nov 14 '05 #6
mu************@ hotmail.com wrote:
I didnt get you
if it is any error please comment the lines "clrscr()" and "getch()"
thanks


The thing is that your code is not ISO C, and that makes it waaaaaaaaaaaay off
topic in this NG. Maybe if you post the question to borland.public. cpp.turbocpp,
you'd get proper help there.
Nov 14 '05 #7
Mark McIntyre wrote:
Thats offtopic here


See? Toldya! ;-)
Nov 14 '05 #8
Michael Mair wrote:


mu************@ hotmail.com wrote:
I didnt get you
if it is any error please comment the lines "clrscr()" and "getch()"

Please ignore "Eltee". He/she/it is a newly acquired troll round here.


That would be "it", Michael. Thanks for your concern.

As for the "newly acquired troll" ... well, like I said, just trying to blend
in. After a week of semi-lurking I realized that if there's a hint of a chance
of your problem not being well within the limits of ISO C specification, what
you're supposed to get is, in a word, "buggeroff" . That's my impression, anyway.
Still learning, though. ;-)
Nov 14 '05 #9
Eltee <el***@hotmail. com> wrote:
mu************@ hotmail.com wrote:

Thought I'd try blending in ... ;-)


You fail to do so.
1 int main(void)
2 {
3 unsigned int un = 3000000000; /* system with 32-bit int */
4 short end = 200; /* and 16-bit short */
5 unsigned int big = 6553;
6 long long verybig = 12345678908642;


<error message="OT in c.l.c" cause="Not ISO C"
redirect="borla nd.public.cpp.t urbocpp">
7 clrscr();


</error>


You are an imbecile, and intentionally so to boot. It is immediately
obvious to anyone who knows C at all that the problem is not with that
line...
8 printf("un = %u and not %d\n", un, un);
9 printf("end = %hd and %d\n", end, end);
10 printf("big = %ld and not %d\n", big,big); /*this one */
11 printf("verybig = %lld and not %ld\n", verybig, verybig);


....but with these. The OP is invoking undefined behaviour by sending
printf() variables of a type it doesn't expect. This has nothing to do
with Turbo C at all; it would be a bug under any implementation. The
only thing that's Turbo-C-specific about this is the precise result of
this UB; IOW, only the specific output is Turbo-dependent, not the fact
that the output is not as expected.

Richard
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

47
5297
by: fb | last post by:
Hi Everyone. Thanks for the help with the qudratic equation problem...I didn't think about actually doing the math...whoops. Anyway... I'm having some trouble getting the following program to work. I want to output a bit pattern from base 10 input. All I get is a zero after the input...I've looked over the code but can't see the problem...any ideas? /* display the bit pattern corresponding to a signed decimal integer */
1
2410
by: vishal | last post by:
Hi, I have a large memory allocated in my program and was trying to print the values read (byte by byte) since the pointer in turboc is 2 bytes, I used a char far pointer to the calculted address and dereferenced it. But some how the value equivalent to deferenced value of the char pointer instead of char far pointer. E.g val=*((char far *)calculated_address); is equivalent to val=*((char *)calculated_address);
3
2404
by: Muhammad Farooq-i-Azam | last post by:
Hi, I am trying to define an arp structure but having problem doing so. I think I have define the correct arp structure but I find myself in a strange problem. The size of structure that I have defined is 28 bytes, but it is reported to be 32 bytes by the sizeof() call. Interestingly, sum of individuals members of the sturcture is 28. However, the sizeof() the entire structure is returned to be 32.
9
1609
by: qbin_wang | last post by:
Dear All: who can tell me where the code of c function of the Turboc c?i want to see the code of function. Thanks!
35
1693
by: fidlee | last post by:
what should be the ouptut of printf("%d",'++'); the ascii value of + is 43... the output comes as 11051 in turboC... (i was surprised it doesnt throw an error on compiling... ) someone explain me as to how this output comes...
2
2624
satyanagendra
by: satyanagendra | last post by:
How To Write Interrupts In Turboc
1
2897
by: vasudevkarthik | last post by:
while installing TurboC/C++ in vista ultimate edition.it says to check whether the application runs in X16 bit system or X32 bit system something like that.Please help me......
0
1563
satyanagendra
by: satyanagendra | last post by:
hi, Can we create DLL using turboc in windows. I am able to create static libraries using turboc. But I don't know how to make DLL files using turboc If it is possible tell me how to make and use DLL files. Regards, N S N Reddy M
7
1539
by: ashjas | last post by:
Hello, I have run this logic on turboc++ 3.0 and it is working fine on it but its not running on msvs2008 c++. i am not able to assign the value like this *temp=*main,where main and temp are char pointers. there is some runtime access violation error on msvs..that i am not able to work out how to resolve.. kind attention and feedback would be invaluable for me...
0
9718
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10617
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10370
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10109
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.