how to check for errors

This is a discussion on how to check for errors within the C Programming forums, part of the General Programming Boards category; I might as well use the code snippet from before ( lol ).... Code: /* Run 1941, write to log ...

  1. #1
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765

    Question how to check for errors

    I might as well use the code snippet from before ( lol )....
    Code:
    	/* Run 1941, write to log */
    			FILE *Exist;
    			if ( ( Exist = fopen("arcade.exe", "r+") ) == NULL )
    			{
    				printf("\nThere was an error loading 1941.\n");
    				printf("\nArcade.exe was not found.");
    				printf("\nYou need arcade.exe to load 1941.");
    				getch();
    			}
    			else
    			{
    				fclose(Exist);
    				if ( ( Exist = fopen("1941.zip", "r+") ) == NULL )
    				{
    					printf("\nThere was an error loading 1941.\n");
    					printf("\n1941 was not found.");
    					getch();
    				}
    				else
    				{
    					fclose(Exist);
    					fprintf(File, "1941\n");
    					printf("\nLoading 1941...");
    					system("arcade 1941 >NUL");
    				}
    			}
    There aren't any return 0's or break's in there to focus on something...

    The last lines of "code"...
    Code:
    printf("\nLoading 1941...");
    system("arcade 1941 >NUL");
    Arcade.exe is a comman line, console program. 1941.zip is going to be opened through arcade.exe. I passed null to the 2nd line there, just so arcade.exe doesn't output it's loading messages, and displays the more user friendly message ( it displays all the files its opening out of 1941.zip....which are odd file names ).

    There could be a case ( actually very likely ), that arcade.exe might run into a problem loading a zip archive. This would be because the zip archive is missing files that arcade.exe was pre-programmed to look for.

    If it runs into that kind of a problem it will idle endlessly at the "Loading 1941..." prompt doing nothing ( the error message is surpressed ).

    Im surpressing the loading messages, because I want the more user friendly ones instead. If it does run into an error, is there a way to catch that and do something with it?

    example:
    Code:
    printf("\nLoading 1941...");
    system("arcade 1941 >NUL");
    if(system("arcade 1941 >NUL") == 0)
    {
    printf("\nAn error occured while proccessing 1941.zip");
    printf("\nThis is because the zip file is not vaild and missing files,");
    printf("\nor the zip file is damaged");
    }
    The world is waiting. I must leave you now.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    I'm not sure if this is what you're looking for, but...
    If If this arcade.exe program actually returns error values, then system("arcade...") should return whatever the status of arcade is upon exiting the program. (I know this is true for UNIX...)

    Of course, this assumes that arcade.exe actually uses special exit values to signify errors, which it should. Something like
    Code:
    i = system("arcade 1941 >NUL");
    printf("\nReturn value %d\n",i);
    Run under conditions where it will commit the error you are expecting should let you reverse engineer the codes.

  3. #3
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765

    ROFL

    Man I been watchin the nooooob's to much ( I am one, but still )..
    What I asked before? That little example code I gave, I tried it and it worked.

    *note to self*: Try any idea's you can come up with before posting...

    Welp, the program I been workin on for a week or two will be completed efficiently. I know enough to do everyting it was planned to do.

    Code:
    	FILE *Tmp;
    	/* Check for arcade.exe */
    	if ( ( Tmp = fopen("arcade.exe", "r+") ) == NULL )
    	{
    		/* If arcade.exe wasn't found */
    		printf("\nArcade.exe was not found!");
    	}
    	else
    	{
    		/* Arcade.exe was found, check for secondary file dkong.zip*/
    		fclose(Tmp);
    		if ( ( Tmp = fopen("dkong.zip", "r+") ) == NULL )
    		{
    			/* If dkong.zip wasn't found */
    			printf("\ndkong.zip not found!");
    		}
    		else
    		{
    			/* Load dkong.zip through arcade.exe */
    			fclose(Tmp);
    			printf("\nLoading Donkey Kong...");
    			system("arcade dkong >NUL");
    			if(system("arcade dkong >NUL") == 0 )
    			{
    				printf("nope");
    			}
    			else
    			{
    				printf(""); /* change to fprintf with the File pointer - not Tmp */
    				/* 
    				This will be the last go line.
    				If all circumstances come back correctly,
    				meaning the zip and exe were found, then
    				the zip was loaded through the exe with 
    				no errors, this else statemnt will have
    				to wait ( due to arcade.exe running ),
    				before it can log that dkong.zip was
    				successfully loaded through arcade.exe
    				*/
    			}
    		}
    	}
    That's still a little basic, but gives the basic idea. Imagine all that code ( with a few extra lines added in later ) as 1 single case in a siwtch statement. Now, imagine doing that 100 times.

    *jots down notes...*
    goto statements, "can" be useful for repeating things endlessly till forced to stop.
    You can display an error message when checking for a file no matter how many times you stretch, poke, or stab at it.
    The world is waiting. I must leave you now.

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765

    To QuestionC

    Arcade.exe was not coded by me, but a team of over 100 programers ( one of them being professional ). Arcade.exe is just my custom build. Arcade.exe ( or the original program of a different name ), is very very professional, so much infact that it emulates arcade machines ( around 3,000 i believe ). If it fails in loading a file it displays exact which files it did not find, and are required. I dont want to see a mile long list of obscure and crazy file names if it fails in loading, after all i'll know why. Instead one simple message is fine ( File is corrupt ...or smiilar ).

    I did run it under error causing conditions ( a zip that was empty but had the same name of a valid archive to load ). They way I have it running now is fine. Arcade.exe does return error values, I just dont want to see them

    thanks anyhow ! :d
    Last edited by Shadow; 10-04-2001 at 07:30 PM.
    The world is waiting. I must leave you now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-06-2010, 12:42 AM
  2. How can i check a directory for certain files?
    By patrioticpar883 in forum C++ Programming
    Replies: 13
    Last Post: 02-01-2008, 05:27 PM
  3. how to check input is decimal or not?
    By kalamram in forum C Programming
    Replies: 3
    Last Post: 08-31-2007, 08:07 PM
  4. Please check this loop
    By Daesom in forum C++ Programming
    Replies: 13
    Last Post: 11-02-2006, 01:52 AM
  5. how to check for end of line in a text file
    By anooj123 in forum C++ Programming
    Replies: 6
    Last Post: 10-25-2002, 12:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21