Jump to content
  • Advertisement
Sign in to follow this  
Auraomega

Ridiculous problem with printf

This topic is 3714 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having a problem with printf functions, they won't work at all for me, I'm sure theres an explanation for why, but I'll be damned if I can work it out. I think the error is likely to be in the makefile, I think I'm missing a library or something silly like that. The offending funcion:
int main(int argc, char* argp[])
{
	if(argc != 2)
	{
		printf("Ussage: 3DWorld.exe [Window Type]\n\n\n[Window Type]\n  0 - Windowed\n  1 - Full Screen");
		system("PAUSE");
		exit(0);
	}

	//handles windowing type, 0 windowed, 1 full screen
	if(strcmp (argp[1], "0") == 0)
	{
		screenType = 0;
	}
	else if(strcmp(argp[1], "1") == 0)
	{
		screenType = 1;
	}
	else
	{
		printf("Error");
		system("PAUSE");
		exit(0);
	}
	WinMain(0, 0, 0, 0); //Nulls sent to WinMain same as CMD appears to send
}
All that happens, at best, is a new CMD window opens with the "Press any key to continue . . ." but no output (even when ran from an instance of CMD). The libraries linked in are "-mwindows -lopengl32 -lglu32 -lstdc++" I know that peice of code itself works fine as I've compiled it working in Code::Blocks without any other functions or libraries. I've had this problem a couple of days, and have taken a wizz on Google to see if I can find anything, but nothing yet, so just wondering if anyone here can help me out? Thanks. -Aura

Share this post


Link to post
Share on other sites
Advertisement
Well, since the printf will only execute if argc != 2 I'm assuming that argc accidentally is equal to two (hint: your usage shows argc == 3... the 3DWorld.exe counts).

Have you tried to set a breakpoint on that line? Have you tried to move it outside of the if statement? What have you tried which didn't work, before asking us?

Share this post


Link to post
Share on other sites
if(argc != 2)

Your program clearly expects one command line argument. So argc should be equal to two in the working case, therefore you should see no print out.

Share this post


Link to post
Share on other sites
As a hint for future problems of this type, if you think printf doesn't work, try something like this before assuming that it is the printf api that has the problem. [grin]


#include <stdio.h>

void main()
{
printf("Testing 1, 2, 3...");
}

Share this post


Link to post
Share on other sites
Nope, I know that the name counts as the first argument so I've just been running 3DWorld.exe, and not 3DWorld.exe 1 or whatever, and besides, to hit a ' system("PAUSE"); ' I have to have the printf first, which just doesn't happen.

Thanks again.
-Aura

EDIT:
@smitty1276:
Already tried it, printf isn't working. I'm not blaming the API because I'm almost certain is a fault of my own (I've even compiled from the MinGW in the Code::Blocks folder to make sure).

Share this post


Link to post
Share on other sites
OK, sorry if that came across as insulting. It was meant to be funny. :-) So, what are you passing in for your cmd line args?

EDIT: Also, I misread the usage statement and thought I saw 2 arguments, but it was [window type] and then its description later.

Share this post


Link to post
Share on other sites
Quote:
Original post by smitty1276
OK, sorry if that came across as insulting. It was meant to be funny. :-) So, what are you passing in for your cmd line args?

EDIT: Also, I misread the usage statement and thought I saw 2 arguments, but it was [window type] and then its description later.


In the future, let's have you be a little more thoughtful when making your attempts at humor.

Could an officer please close this thread?

Share this post


Link to post
Share on other sites
Thats alright, I'm just a bit tired, ignore my edginess.

I've tried various things:
3D_World.exe //argc = 1
3D_World.exe 2 //argp[1] != 0 || 1
3D_World.exe 0 0 // argc = 3
3D_World.exe 0 // argc + argp correct

the only one which works as expected is 3D_World.exe 0, which gives me a windowed loading screen, all the others close as they should do, but don't give me an output.

-Aura

Share this post


Link to post
Share on other sites
Weird. A couple of things to try:

  • fprintf(stderr, "Hello");
    This will print to the stderr stream instead of stdout. They're usually the same but maybe your system is redirecting one of them for some reason

  • fflush(0);
    This will flush all output streams, sending the data to the screen if it's buffered.



I know I'm reaching, but I can't see what your problem would be.

Share this post


Link to post
Share on other sites
Quote:
Original post by Auraomega
The libraries linked in are "-mwindows -lopengl32 -lglu32 -lstdc++"


It's been a while since I last compiled a Win32 app, but I think the -mwindows flag makes your program use the Win32 (i.e. not Console) subsystem. That means your process is not given a console when it starts -- probably executing system("pause"); makes the system allocate a console for your app -- but at the point at which the printf call is made, there is no console yet and so the output goes nowhere.

Try dropping the -mwindows flag -- or allocate yourself a console.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!