Problem: fprintf printing to console

On Windows/SDL/VS.net the following code:

fprintf(stdout, “Hello World!\n”);

prints to my console window. Why?

Thanks

On Windows/SDL/VS.net the following code:

fprintf(stdout, “Hello World!\n”);

prints to my console window. Why?

Err…

Is this a homework question, or are you just really new to C?

I’m going to assume you’re a beginner and give you some hints,
because figuring out this sort of thing on your own will help
you learn better than me just telling you the answer.

  1. What you’ve posted is platform-independent code. It would
    work equally well under Windows/Linux/Solaris/VMS/PDP-11/whatever.

  2. It only makes use of the basic ANSI system libraries (in particular,
    the function fprintf() declared in stdio.h). So it doesn’t require
    SDL, .net, or any other library.

  3. It’s pure C, making no use of C++ constructs.

If the above doesn’t make sense (or even if it does), I highly
recommend ‘The C Programming Language’ by Kernighan and Ritchie.
You want the second edition, which is ANSI C. This is the
fundamental book on the language.

Ron Steinke> From: “E. Nicholas Morgan” <e.n.morgan at mat.ucsb.edu>

Thanks for the reply Ron,

I am fairly new to C, so I apologize if my questions are out of line.
If so, let me know.

In Ernest Pazera’s book “Focus on SDL” he writes, “SDL automatically
maps these [stdout or stderr] to files entitled stdout.txt and
stderr.txt, respectively.” Also, his example programs demonstrate this.
So, I was expecting that behavior. Where did I go wrong?

Thanks,
Nicholas> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
rsteinke at w-link.net
Sent: Wednesday, September 10, 2003 10:30 PM
To: sdl at libsdl.org
Subject: Re: [SDL] Problem: fprintf printing to console

From: “E. Nicholas Morgan” <@E_Nicholas_Morgan>

On Windows/SDL/VS.net the following code:

fprintf(stdout, “Hello World!\n”);

prints to my console window. Why?

Err…

Is this a homework question, or are you just really new to C?

I’m going to assume you’re a beginner and give you some hints, because
figuring out this sort of thing on your own will help you learn better
than me just telling you the answer.

  1. What you’ve posted is platform-independent code. It would work
    equally well under Windows/Linux/Solaris/VMS/PDP-11/whatever.

  2. It only makes use of the basic ANSI system libraries (in particular,
    the function fprintf() declared in stdio.h). So it doesn’t require SDL,
    .net, or any other library.

  3. It’s pure C, making no use of C++ constructs.

If the above doesn’t make sense (or even if it does), I highly recommend
’The C Programming Language’ by Kernighan and Ritchie. You want the
second edition, which is ANSI C. This is the fundamental book on the
language.

Ron Steinke


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hi Nicholas!
The Problem ist that most IDEs map these, too. At least that’s the
case for KDevelop and Eclipse. I guess the same happens with VC++,
mapping it to a Konsole so that a developer will not have to check
the files to see what went on.
regards
Matthias

Am Mittwoch, 10 September 2003 schrieben Sie:

Thanks for the reply Ron,

I am fairly new to C, so I apologize if my questions are out of line.
If so, let me know.

In Ernest Pazera’s book “Focus on SDL” he writes, “SDL automatically
maps these [stdout or stderr] to files entitled stdout.txt and
stderr.txt, respectively.” Also, his example programs demonstrate
this.
So, I was expecting that behavior. Where did I go wrong?

Thanks,
Nicholas

rsteinke at w-link.net

On Windows/SDL/VS.net the following code:

fprintf(stdout, “Hello World!\n”);

prints to my console window. Why?

Err…

Is this a homework question, or are you just really new to C?

I’m going to assume you’re a beginner and give you some hints, because
figuring out this sort of thing on your own will help you learn better
than me just telling you the answer.

  1. What you’ve posted is platform-independent code. It would work
    equally well under Windows/Linux/Solaris/VMS/PDP-11/whatever.

  2. It only makes use of the basic ANSI system libraries (in particular,
    the function fprintf() declared in stdio.h). So it doesn’t require
    SDL,
    …net, or any other library.

  3. It’s pure C, making no use of C++ constructs.

If the above doesn’t make sense (or even if it does), I highly
recommend> -----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Sent: Wednesday, September 10, 2003 10:30 PM
To: sdl at libsdl.org
Subject: Re: [SDL] Problem: fprintf printing to console

From: “E. Nicholas Morgan” <e.n.morgan at mat.ucsb.edu>
‘The C Programming Language’ by Kernighan and Ritchie. You want the
second edition, which is ANSI C. This is the fundamental book on the
language.

Ron Steinke


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Did you build a Release Version and used the original
sdl.dll?

sdl.dll links to msvcrt.dll.
Maybe linking to both msvcrt.dll and the Debug-Version
msvcrtd.dll may cause such an effect.

You also could use the tool “depends” (Dependency Viewer)
on your exe if you are not sure about this.

Thomas> ----- Original Message -----

From: e.n.morgan@mat.ucsb.edu (E. Nicholas Morgan)
To:
Sent: Thursday, September 11, 2003 7:47 AM
Subject: RE: [SDL] Problem: fprintf printing to console

Thanks for the reply Ron,

I am fairly new to C, so I apologize if my questions are out of line.
If so, let me know.

In Ernest Pazera’s book “Focus on SDL” he writes, “SDL automatically
maps these [stdout or stderr] to files entitled stdout.txt and
stderr.txt, respectively.” Also, his example programs demonstrate this.
So, I was expecting that behavior. Where did I go wrong?

Thanks,
Nicholas

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
rsteinke at w-link.net
Sent: Wednesday, September 10, 2003 10:30 PM
To: sdl at libsdl.org
Subject: Re: [SDL] Problem: fprintf printing to console

From: “E. Nicholas Morgan” <e.n.morgan at mat.ucsb.edu>

On Windows/SDL/VS.net the following code:

fprintf(stdout, “Hello World!\n”);

prints to my console window. Why?

Err…

Is this a homework question, or are you just really new to C?

I’m going to assume you’re a beginner and give you some hints, because
figuring out this sort of thing on your own will help you learn better
than me just telling you the answer.

  1. What you’ve posted is platform-independent code. It would work
    equally well under Windows/Linux/Solaris/VMS/PDP-11/whatever.

  2. It only makes use of the basic ANSI system libraries (in particular,
    the function fprintf() declared in stdio.h). So it doesn’t require SDL,
    .net, or any other library.

  3. It’s pure C, making no use of C++ constructs.

If the above doesn’t make sense (or even if it does), I highly recommend
’The C Programming Language’ by Kernighan and Ritchie. You want the
second edition, which is ANSI C. This is the fundamental book on the
language.

Ron Steinke


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

[…]

In Ernest Pazera’s book “Focus on SDL” he writes, “SDL
automatically maps these [stdout or stderr] to files entitled
stdout.txt and stderr.txt, respectively.”

As far as SDL is concerned, this only happens on platforms where you
normally don’t run things from a console; ie where the user would
have no chance of seeing any stdout or stderr output.

This redirection should happen on Win32 normally, but I assume
you’re either running your application from inside the IDE (so the
IDE overrides SDL’s redirection somehow), or you’re building a “Win32
console” app, rather than a GUI app.

(I don’t develop on Windows, so I can’t comment more specifically on
how to configure your tools.)

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Thursday 11 September 2003 07.47, E. Nicholas Morgan wrote:

I think the redirection only happens when you build a non-console win32 app.
You should be able to change your project from a console app to a
non-console app somewhere in the project settings window in visual studio.
My memory is a bit hazy on this - you might find it quicker to simply create a
new project instead…

Ben.On Thursday 11 September 2003 6:47 am, E. Nicholas Morgan wrote:

In Ernest Pazera’s book “Focus on SDL” he writes, “SDL automatically
maps these [stdout or stderr] to files entitled stdout.txt and
stderr.txt, respectively.” Also, his example programs demonstrate this.
So, I was expecting that behavior. Where did I go wrong?

Thank you all for your input.

I fixed my problem. In my linker settings I had - "/SUBSYSTEM:console"
instead of “/SUBSYSTEM:windows”

Nicholas> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Ben Campbell
Sent: Thursday, September 11, 2003 10:52 AM
To: sdl at libsdl.org
Subject: Re: [SDL] Problem: fprintf printing to console

On Thursday 11 September 2003 6:47 am, E. Nicholas Morgan wrote:

In Ernest Pazera’s book “Focus on SDL” he writes, “SDL automatically
maps these [stdout or stderr] to files entitled stdout.txt and
stderr.txt, respectively.” Also, his example programs demonstrate
this. So, I was expecting that behavior. Where did I go wrong?

I think the redirection only happens when you build a non-console win32
app. You should be able to change your project from a console app to a

non-console app somewhere in the project settings window in visual
studio. My memory is a bit hazy on this - you might find it quicker to
simply create a
new project instead…

Ben.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl