Due to server problems the website is temporarily offline! Visit http://www.smorgasbordet.com/pellesc/ to download Pelles C.
#include <stdio.h>#include <string.h>#include <io.h>#include <windows.h>void RedirectStdOut(void);int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow ){RedirectStdOut(); printf( "zz" ); getchar(); // WHY this does not work ? return 0;}void RedirectStdOut(void){ CONSOLE_SCREEN_BUFFER_INFO csbi; // Try creating a new console window. if (!AllocConsole()) return; // Set the screen buffer to be larger than normal. if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) { csbi.dwSize.Y = 1000; // any useful number... SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), csbi.dwSize); } // Redirect "stdout" to the console window. fclose(stdout); setbuf(stdout, NULL); FILE *fp = fdopen(_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), 0), "w"); *stdout = *fp;}
#include <stdio.h>#include <io.h>#include <windows.h>#include <fcntl.h>#include <conio.h>void RedirectStd(void);int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow ){ RedirectStd(); printf( "\nType any key to continue...\n" ); getchar();return 0;}void RedirectStd(void){int hCrt = -1;FILE *hf = NULL;int i = -1; AllocConsole(); hCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT); hf = _fdopen(hCrt, "w"); *stdout = *hf; i = setvbuf(stdout, NULL, _IONBF, 0); printf( "stdout//" ); hCrt = _open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE), _O_TEXT); hf = _fdopen(hCrt, "r"); *stdin = *hf; i = setvbuf(stdin, NULL, _IONBF, 0); printf( "stdin//" ); hCrt = _open_osfhandle((long)GetStdHandle(STD_ERROR_HANDLE), _O_TEXT); hf = _fdopen(hCrt, "w"); *stderr = *hf; i = setvbuf(stderr, NULL, _IONBF, 0); printf( "stderr//" );}