Hello Monster,
I'm pretty sure chdir works fine for me, using gcc. I tested with a simple program I wrote that opened a document or executed a program that wasn't in the working directory ( without providing the path to the file ). This worked. It opened just as if I were to add "path c:\path\to\my\stuff" into my program.
I have a program that I am trying to break down, because it compiles fine, yet when excecuting certain parts ot it, it bombs back to Windows saying, "This program has performed an illegal operation and will be shut down." - Hum, why?
Code:
int run_1942()
{
FILE * Tmp;
FILE * Log;
time_t hold_time;
printf("Loading 1942...");
system("choice /c:. /t:.,03 /n >NUL");
if ( ( Tmp = fopen("c:\\emulation\\mameb16\\mamepp.exe", "r+") ) == 0)
{
// Emulator was not found. Display a message.
printf("\n\nThere was an error loading 1942!\n");
printf("Mamepp.exe was not found. You need this file to run the game.\n\n");
printf("Press any key...");
getch();
// Emulator was not found. Log the error.
hold_time=time(NULL);
Log = fopen("log.htm", "a");
fprintf(Log, "++++++++++++++++++++++++++++++\n");
fprintf(Log, ctime(&hold_time));
fprintf(Log, "Menu errored:\n");
fprintf(Log, "1942\n");
fprintf(Log, "Emulator was not found.\n");
fprintf(Log, "++++++++++++++++++++++++++++++\n\n");
}
else
{
fclose(Tmp);
if ( ( Tmp = fopen("c:\\emulation\\mameb16\\roms\\1942.zip", "r+") ) == 0)
{
// Rom was not found. Display a message.
printf("\n\nThere was an error loading 1942!\n");
printf("The rom was not found. You need this file to run the game.\n\n");
printf("Press any key...");
getch();
// Rom was not found. Log the error.
hold_time=time(NULL);
fprintf(Log, "++++++++++++++++++++++++++++++\n");
fprintf(Log, ctime(&hold_time));
fprintf(Log, "Menu errored:\n");
fprintf(Log, "1942\n");
fprintf(Log, "Rom file was not found.\n");
fprintf(Log, "++++++++++++++++++++++++++++++\n\n");
}
else
{
fclose(Tmp);
hold_time=time(NULL);
fprintf(Log, "++++++++++++++++++++++++++++++\n");
fprintf(Log, ctime(&hold_time));
fprintf(Log, "Menu ran:\n");
fprintf(Log, "1942\n");
fprintf(Log, "++++++++++++++++++++++++++++++\n\n");
chdir("mameb16"); // The path were mamepp.exe exists
if(system("mamepp 1942 >NUL") == 1)
{
// Rom failed to load. Display a message.
printf("\n\nThere was an error loading 1942!\n");
printf("Possible causes:\n");
printf("The romset is incomplete.\n");
printf("The romset is corrupt.\n");
printf("There is not enough memory to run this game.\n\n");
printf("Press any key...");
getch();
// Rom failed to load. Log the error.
hold_time=time(NULL);
fprintf(Log, "++++++++++++++++++++++++++++++\n");
fprintf(Log, ctime(&hold_time));
fprintf(Log, "Menu errored:\n");
fprintf(Log, "1942\n");
fprintf(Log, "Rom file failed to load.\n");
fprintf(Log, "Run a check on the romset.\n");
fprintf(Log, "++++++++++++++++++++++++++++++\n\n");
}
else
{
// All files were found. Files loaded fine.
hold_time=time(NULL);
fprintf(Log, "++++++++++++++++++++++++++++++\n");
fprintf(Log, ctime(&hold_time));
fprintf(Log, "Menu closed:\n");
fprintf(Log, "1942\n");
fprintf(Log, "++++++++++++++++++++++++++++++\n\n");
}
}
}
system("cd..");
return 0;
}
Keep in mind, this code is from part of a large program that needs to be heavily modularized.
I was using Turbo C++ before to write this program. I tried to compile it with Turbo C++ upon completion ( 7 1/2 k in lines ), and it runs out of memory during compilation. I run out and get GCC. I got the Win32 version, btw. After some configuring ( adding code into a newly created standard include file for clearing the screen, and forcing full screen upon startup ), I get it to compile. ( I am taking it one step at a time ). Ok, it compiles! I then convert my other 2 WIP programs ( much much smaller, few hundred lines ... ) over to compile with gcc. They compile, and execute just fine.
Everything compiles, my special function prototypes work just fine, no errors are given on compilation. This large program starts up fine, and idles just fine, but whenever you go to execute one of the function prototypes, it crashes.
This, is why I asked the chdir question. I am trying to break the program down. There are several other functions identical to this one, only they execute other "games". They all cause an error upon execution. I don't know if it is the ....I don't know what it is.