fprintf not working

Started by
0 comments, last by SnotBob 15 years, 11 months ago

#include "SDL/SDL.h"
#include <stdio.h>
#include <stdlib.h>

SDL_Surface *g_pMainSurface = NULL;
SDL_Event g_Event;

int main( int argc, char *argv[] )
{
	if ( SDL_Init( SDL_INIT_VIDEO ) == -1 )
	{
		fprintf( stderr, "Could not initialize SDL!\n" );
		exit( 1 );
	}
	else
	{
		fprintf( stdout, "SDL initialized properly!\n");
		atexit( SDL_Quit );
	}

	g_pMainSurface = SDL_SetVideoMode( 640, 480, 0, SDL_ANYFORMAT );

	if (!g_pMainSurface)
	{
		fprintf( stderr, "Could not create main surface!\n" );
		exit( 1 );
	}

	for ( ;; )
	{
		if ( SDL_WaitEvent( &g_Event ) == 0 )
		{
			fprintf( stderr, "Could not create main surface!\n");
			exit( 1 );
		}

		// check the type of event
		if ( g_Event.type == SDL_QUIT )
		{
			fprintf( stdout, "Quit event has occurred.\n");
			break;
		}
	}
	fprintf( stdout, "Terminating program normally.\n" );
	return( 0 );
}
There is no file that is being created. fprintf does print out to a file right?
Advertisement
Fprintf() prints to a file handle. Stdout and stderr are handles to the standard output and standard error streams, which typically go to the console, so fprintf(stdout,...) is actualy the same as printf(...). On Windows, SDL overrides them to files for convenience. You need to use fopen() to open a handle to a file.

This topic is closed to new replies.

Advertisement