check my code ( if statement, file existance )

This is a discussion on check my code ( if statement, file existance ) within the C Programming forums, part of the General Programming Boards category; You can read through this if you want.......I just took >NUL of the system statement and the file im trying ...

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

    check my code ( if statement, file existance )

    You can read through this if you want.......I just took >NUL of the system statement and the file im trying to open is denied for access. Im leaving it open somewhere before I execute it.......I wanna try to figure it out, if i can't, help me then.....

    Someone on here showed how to check for file existance. I'm checking for the existance of 2 files at once, in one straight sweep. Here's the code...
    Code:
    int main()
    {
    	/* FILE * Tmp; - I found I dont need this */
    	/* Check for arcade.exe */
    	if(fopen("d:\\arcade.exe", "r+") == 0)
    	{
    		/* If arcade.exe wasn't found */
    		printf("\nArcade.exe was not found!");
    	}
    	else
    	{
    		/* Arcade.exe was found, check for secondary file 1941.zip*/
    		if(fopen("d:\\1941.zip", "r+") == 0)
    		{
    			/* If 1941.zip wasn't found */
    			printf("\n1941.zip not found!");
    		}
    		else
    		{
    			/* Load 1941.zip through arcade.exe */
    			printf("\nLoading 1941");
    			system("arcade 1941 >NUL");
    		}
    	}
    	return 0;
    }
    Now when I put this program into the folder where these files are clearly located ( and work from the command promt ). I can type arcade 1941 >NUL from the comand prompt and it works just fine. For some reason this program is skipping the system command in this program. IT IS printing the printf statement right before it though.....HU?

    side note ( a few sec later ):
    I can get all of the messages. I just move the file it's looking for into a different directory and it displays the proper messages stating that the certain files that are needed weren't found. I can't get that dang system command to execute though? Everything else works fine...

    I replaced the arcade.exe 1941 system call with c:\\windows\\write.exe and that works! The only reason it's just arcade.exe with no path is because im running this program from the directory arcade.exe is in. Arcade.exe then does more extensive searching for the secondary file.
    Last edited by Shadow; 10-04-2001 at 10:57 AM.
    The world is waiting. I must leave you now.

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

    on the last post........

    The if statement structure was setup just fine for checking the files.....If this statement works:

    if(fopen("d:\\arcade.exe", "r+") == 0)

    But that doesn't work, because when I call the program it then tries to open it but the access is denied because this program is still holding on to it. If I try to close it fclose("d:\\arcade.exe") it complains.

    Doing this:
    FILE * Tmp;
    /* Check for arcade.exe */
    if(fopen("d:\\arcade.exe", "r+") == NULL)

    then fclose(Tmp); later on....doesn't work either.

    I can't figure it out....here's the latest code ( file existance ...checking for more then one file )

    Code:
    int main()
    {
    	FILE * Tmp;
    	/* Check for arcade.exe */
    	if(fopen("d:\\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 1941.zip*/
    		fclose(Tmp);
    		if(fopen("d:\\1941.zip", "r+") == NULL)
    		{
    			/* If 1941.zip wasn't found */
    			printf("\n1941.zip not found!");
    		}
    		else
    		{
    			/* Load 1941.zip through arcade.exe */
    			fclose(Tmp);
    			printf("\nLoading 1941");
    			system("arcade 1941");
    		}
    	}
    	return 0;
    }
    The world is waiting. I must leave you now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  3. Check for file existance...
    By Junior89 in forum C++ Programming
    Replies: 10
    Last Post: 02-05-2005, 03:42 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM

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