problem with different putchar()'s - please help 
Author Message
 problem with different putchar()'s - please help

I am writing a function which sends an raw gif image file through stdio
using a loop of putchar() functions (not printf or puts becuase of the
character handling they do) for a cgi program and when I compile it with a
win32 compiler, putchar prints an 0x0D before each 0x0A which creates
unwanted characters and destroys the file.  Under SunOS, (which i dont want
this program in), however, it seems to just put in the 0x0A like all the
other characters.  So far I havent been able to figure out how to print the
file in tact to stdio in NT.  The putchar() function seems to be the most
basic for printing to the screen, is there anyway to bypass its features?

Thanks,
Phil "KINGCOBRA" Pesek



Fri, 23 Nov 2001 03:00:00 GMT  
 problem with different putchar()'s - please help
To prevent this, you need to change the mode of stdout to binary. Without
this step, DOS assumes text mode and attaches a carriage return to each line
feed. It will also stop the transfer entirely at the first Ctrl+Z.

This is not about putchar(), printf() or puts(). It is more basic than that.

You will need to consult your compiler's documentation to change the mode of
stdout.

--

Paul Lutus
www.arachnoid.com

Quote:

>I am writing a function which sends an raw gif image file through stdio
>using a loop of putchar() functions (not printf or puts becuase of the
>character handling they do) for a cgi program and when I compile it with a
>win32 compiler, putchar prints an 0x0D before each 0x0A which creates
>unwanted characters and destroys the file.  Under SunOS, (which i dont want
>this program in), however, it seems to just put in the 0x0A like all the
>other characters.  So far I havent been able to figure out how to print the
>file in tact to stdio in NT.  The putchar() function seems to be the most
>basic for printing to the screen, is there anyway to bypass its features?

>Thanks,
>Phil "KINGCOBRA" Pesek



Fri, 23 Nov 2001 03:00:00 GMT  
 problem with different putchar()'s - please help
On Mon, 7 Jun 1999 01:44:49 -0500, "Philip Pesek"

Quote:
> I am writing a function which sends an raw gif image file through stdio
> using a loop of putchar() functions (not printf or puts becuase of the
> character handling they do) for a cgi program and when I compile it with a
> win32 compiler, putchar prints an 0x0D before each 0x0A which creates
> unwanted characters and destroys the file.  Under SunOS, (which i dont want
> this program in), however, it seems to just put in the 0x0A like all the
> other characters.  So far I havent been able to figure out how to print the
> file in tact to stdio in NT.  The putchar() function seems to be the most
> basic for printing to the screen, is there anyway to bypass its features?

> Thanks,
> Phil "KINGCOBRA" Pesek

<Jack>

Your first mistake is thinking that putchar() and other <stdio.h>
functions output to a screen.  They do not.  They send their output to
streams.  On some platforms and some operating systems such a stream
might happen to be connected to a driver for a display screen but
neither the C language nor the definition of putchar() require this to
be so.  In your particular case you most certainly do not want the
output of putchar() sent to the Windows text mode console window, you
want it to go somewhere else completely.

By definition, all files in C are opened in text mode, unless
specifically opened in binary mode.  If an operating environment uses
something other than a plain '\n' to indicate the end of lines in text
files the C standard requires that input and output from and to text
files translate between whatever the operating system uses and a plain
'\n'.

So standard C requires that when you output '\n' to a text mode stream
the DOS/Windows end of line sequence "\r\n" is produced.

The solution?  Open a file in binary mode and output to it, or use
freopen() to reopen stdout in binary mode.  Note that this might not
be possible unless the operating system supplies a file name to do
this with.

There might also be a non-standard, compiler specific function to
change the mode of stdout to binary with you build your program or
once it begins execution.  This would not be part of standard C and is
beyond the scope of this newsgroup.

Look up console functions in your online help or ask in a Windows
programming newsgroup or one which supports your particular brand of
compiler.

</Jack>
--
Do not email me with questions about programming.
Post them to the appropriate newsgroup.
Followups to my posts are welcome.



Fri, 23 Nov 2001 03:00:00 GMT  
 problem with different putchar()'s - please help

Quote:

> I am writing a function which sends an raw gif image file through stdio
> using a loop of putchar() functions (not printf or puts becuase of the
> character handling they do) for a cgi program and when I compile it with a
> win32 compiler, putchar prints an 0x0D before each 0x0A which creates
> unwanted characters and destroys the file.  Under SunOS, (which i dont want
> this program in), however, it seems to just put in the 0x0A like all the
> other characters.  So far I havent been able to figure out how to print the
> file in tact to stdio in NT.  The putchar() function seems to be the most
> basic for printing to the screen, is there anyway to bypass its features?

Phil...

I'm pretty sure that we're off-topic for comp.lang.c, so I'll be as brief as
possible. You didn't mention your compiler so I'll talk about the one I last
used in an MS environment, Borland 3.?

Borland provided an extern int _fmode variable which defaulted to O_TEXT on
startup. You could set _fmode = O_BINARY to override the default behavior. M$
may have provided the same sort of nonstandard hook (I don't know; but expect
that you can use the on-line help facility in your IDE to find out.

Borland also provided int setmode(int fd,int mode) to permit changing the mode
of an open()'d file.

Morris Dovey
West Des Moines, Iowa USA



Fri, 23 Nov 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. putchar('\a') (more gubbins)

2. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

3. Problem with array's PLEASE HELP

4. Modeless Dialog Focus problem (I'm a Newbie please Help)

5. Please help!!!!Please help!!!!Please help!!!!

6. Same EVC + Different PC's = arm exe DIFFERENT file size (iPAQ)

7. Help!! Putchar()

8. Help!! Putchar()

9. Please Help !! - Copy file between different directories

10. Dialog size/layout problem on different OS's

11. 0, '\0', and NULL (was: help , please)

12. Please please help!!!!!!!!! (link problems)

 

 
Powered by phpBB® Forum Software