Click to See Complete Forum and Search --> : Anomolous Results


MrNewbie
02-15-2001, 04:15 PM
I have this code:

#include <stdio.h>

main()
{
static unsigned char DBL_BOX[6] = {201, 187, 186, 200, 188, '\n'};
static unsigned char SGL_BOX[6] = {218, 191, 179, 192, 217, '\n'};

printf("%s %s", DBL_BOX, SGL_BOX);
}


I compiled it with Turbo C and got this result:

http://www.super8video.f2s.com/1.gif
http://www.super8video.f2s.com/2.gif
%s %s http://www.super8video.f2s.com/2.gif
%s %s

And then with DJGPP (Win32 GNU Port) and got this:

http://www.super8video.f2s.com/1.gif
http://www.super8video.f2s.com/2.gif
http://www.super8video.f2s.com/2.gif


Whats up with that? Its working, printing the correct things, but why is the second string being printed twice both times and %s being printed twice in the Turbo C version?

Also, I found if I did this:


#include <stdio.h>

main()
{
static unsigned char DBL_BOX[6] = {201, 187, 186, 200, 188, '\n'};
static unsigned char SGL_BOX[6] = {218, 191, 179, 192, 217, '\n'};
puts(DBL_BOX);
}


It works fine! Prints both of the strings, thats just weird!
MrNewbie

Edit: The characters were messed up.

[ 15 February 2001: Message edited by: MrNewbie ]

jemfinch
02-15-2001, 06:06 PM
I can't guarantee anything here, but you should be terminating each of those strings with a \0.

Jeremy

MrNewbie
02-15-2001, 06:46 PM
Damn! Your right! I always overlook the simple stuff! Thanks a lot.
MrNewbie