Thread: BAsic problem with error handling in sdl using printf

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    7

    BAsic problem with error handling in sdl using printf

    Hi all,

    I have started sdl and have sucesfully done some basic graphics which correctly handle collisions ......I am starting a new basic program and when sdl is initialised depending on the outcome i want to use printf and it says "SDL init succesful" or sdl init failed .......the code I have so far is below and none of the printf statements display in visual studio 6

    Code:
    #include "SDL/SDL.h"
    #include <string>
    #include <stdio.h>
    #include "SDL/SDL_image.h"
    
    //set global vars for screen width height and bts per pixel they are constants
    const int SCREEN_WIDTH = 640;
    const int SCREEN_HEIGHT = 480;
    const int SCREEN_BPP = 32;
    
    //set dot attribs
    const int dot_h = 20;
    const int dot_w = 20;
    
    //set global surfaces
    SDL_Surface *dot = NULL;
    SDL_Surface *screen = NULL;
    
    //int SDL_Init(Uint32 flags);
    
    bool startsdl()
    {
    	//init sdl and check if started ok if not retuen false
    	if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
    	{
          return false;
    	}
    
    	return true;
    }
    
    int main(int argc, char *args[])
    {
    	//quit prog status
    	bool quit = false;
    	//init sdl
    	if(startsdl() == false)
    	{
    		printf("sdl int failed \n");
    	
    	}
    	printf("sdl int worked \n");
    	return 0;
    }

    edit ----->
    just realised the utput is going to stdout.txt how can I get the output to show in the visual c++ 6 small window at the bottom
    thanks
    david
    Last edited by redwing26; 07-31-2006 at 10:42 AM.

  2. #2
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    A quick Google search for "redirect stdout" turned up this site.

    It gives the suggestion of trying:
    Code:
    freopen( "CON", "w", stdout );

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    7
    Yeah I constantly check google and I never found anything thats why I came here also I dont find some of the commands in the manuals in the format command (key,int,flag,etc,etc) very helpful for solving some of my problems I prefer good examples relevant to what im trying to do like the above.

    Thanks
    David

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems reading entered race times C
    By loopymoo26 in forum C Programming
    Replies: 12
    Last Post: 05-23-2009, 07:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. Simple C question: user input to repeat a loop
    By evernaut in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 09:23 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Azbia - a simple RPG game code
    By Unregistered in forum Game Programming
    Replies: 11
    Last Post: 05-03-2002, 06:59 PM