•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,534 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,047 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1249 | Replies: 13
![]() |
•
•
Join Date: Oct 2007
Posts: 16
Reputation:
Rep Power: 2
Solved Threads: 0
Finished my code, it compiles, but when i use build bersion, there is always an error
#1
Oct 12th, 2007
ok so i made a code that makes something compatible with a never version ( it is not important). This is my code:
it works fine when i debug (i use ms visual C++). But when i use the build version, it always "encounters a problem" and has to close. If someone knows why this is happening, that would be great.
Thanks in advance
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
char File[150], re[4];
string line[5000];
string response;
int counter=0;
size_t found;
string strtofind[]={"oolean1", "oolean2", "oolean3", "nteger1", "nteger2", "nteger3",
"tring1", "tring2", "tring3"};
string changestr[]={"ooleans[0]", "ooleans[1]", "ooleans[2]", "ntegers[0]", "ntegers[1]",
"ntegers[2]", "trings[0]", "trings[1]", "trings[2]"};
int index;
cout<<" Script Converter\n";
cout<<"Would you like to convert a SRL 3.81 script to SRL 4? (yes or no) \n";
cin>>re;
_strupr_s(re);
response=re;
if(response== "YES") {
cout<<"Please enter the name of the file (C:/Program Files/example.scar)"<<endl;
cout<<"the location is not needed if this program and the script are in the same folder\n";
cin.ignore ( 150, '\n' ); //flush the input stream
cin.getline(File, 150);
cout<<"Now Converting "<< File<< " to SRL 4 ..."<<endl;
ifstream fin;
ofstream fout;
fin.open(File);
if(fin){
while (getline(fin, line[counter])){
counter++;
}
for(counter=0; counter<5000; counter++){
for(index=0; index<11; index++){
found=line[counter].find(strtofind[index]);
if (found!=string::npos){
line[counter].replace(int(found), strtofind[index].length(), changestr[index]);
}
}
}
fout.open(File);
fout<<"{Script Converted to SRL 4 by Macrosoft's Script Converter}\n";
for(counter=0; counter<5000; counter++){
fout<<line[counter]<<"\n";
}
cout<<"Finished converting script\n";
}
else {
cout<<"Failed to open file\n";
}
fin.close();
fout.close();
}
else if(response == "NO"){
cout<<"Closing Program...\n";
}
else{
cout<<"Response not understood. Closing Program...\n";
}
system("PAUSE");
return 0;
}it works fine when i debug (i use ms visual C++). But when i use the build version, it always "encounters a problem" and has to close. If someone knows why this is happening, that would be great.
Thanks in advance
Re: Finished my code, it compiles, but when i use build bersion, there is always an error
#2
Oct 12th, 2007
•
•
Join Date: Oct 2007
Posts: 16
Reputation:
Rep Power: 2
Solved Threads: 0
Re: Finished my code, it compiles, but when i use build bersion, there is always an e
#3
Oct 12th, 2007
Re: Finished my code, it compiles, but when i use build bersion, there is always an e
#4
Oct 12th, 2007
>SRL 3.81 to SRL 4.exe has encountered a problem and needs to close.
Classic runtime error. It means you're probably overrunning a buffer somewhere. Run your program in debug mode and step through it until you hit the error. That'll give you a good idea of where the error is being manifested, and you can trace it back the cause from there.
Classic runtime error. It means you're probably overrunning a buffer somewhere. Run your program in debug mode and step through it until you hit the error. That'll give you a good idea of where the error is being manifested, and you can trace it back the cause from there.
I'm here to prove you wrong.
•
•
Join Date: Oct 2007
Posts: 16
Reputation:
Rep Power: 2
Solved Threads: 0
Re: Finished my code, it compiles, but when i use build bersion, there is always an e
#5
Oct 12th, 2007
Re: Finished my code, it compiles, but when i use build bersion, there is always an e
#6
Oct 13th, 2007
Re: Finished my code, it compiles, but when i use build bersion, there is always an e
#7
Oct 13th, 2007
> If someone knows why this is happening, that would be great.
I've got two pretty good ideas where the problem is (ok, 3 actually).
> while (getline(fin, line[counter]))
What stops this over stepping the array?
> for(counter=0; counter<5000; counter++)
Why 5000 and not the number of lines you read?.
Since this is the same variable, why did you even bother with counting them?
> for(index=0; index<11; index++)
How many entries are there in strtofind ?
Come to think of it, why do you even bother storing the whole file in memory at all. "Read a line, do the subs, write out the line" would work just as well in a loop.
I've got two pretty good ideas where the problem is (ok, 3 actually).
> while (getline(fin, line[counter]))
What stops this over stepping the array?
> for(counter=0; counter<5000; counter++)
Why 5000 and not the number of lines you read?.
Since this is the same variable, why did you even bother with counting them?
> for(index=0; index<11; index++)
How many entries are there in strtofind ?
Come to think of it, why do you even bother storing the whole file in memory at all. "Read a line, do the subs, write out the line" would work just as well in a loop.
•
•
Join Date: Oct 2007
Posts: 16
Reputation:
Rep Power: 2
Solved Threads: 0
Re: Finished my code, it compiles, but when i use build bersion, there is always an e
#8
Oct 13th, 2007
•
•
•
•
>i dont get error when i run it in debug mode...
Then sprinkle debug messages everywhere and run it in release mode. Are you really this helpless or are you just trying to get us to do your troubleshooting for you?
i didn't get what you just said, yes i am that helpless
•
•
•
•
> If someone knows why this is happening, that would be great.
I've got two pretty good ideas where the problem is (ok, 3 actually).
> while (getline(fin, line[counter]))
What stops this over stepping the array?
> for(counter=0; counter<5000; counter++)
Why 5000 and not the number of lines you read?.
Since this is the same variable, why did you even bother with counting them?
> for(index=0; index<11; index++)
How many entries are there in strtofind ?
Come to think of it, why do you even bother storing the whole file in memory at all. "Read a line, do the subs, write out the line" would work just as well in a loop.
>What stops this over stepping the array?
huh?
>Why 5000 and not the number of lines you read?.
>Since this is the same variable, why did you even bother with counting them?
already fixed it, but im trying to use new and delete for the array of line, but running through some problems

>How many entries are there in strtofind ?
9, dk why i put 11...
>Come to think of it, why do you even bother storing the whole file in memory at all. "Read a line, do
> the subs, write out the line" would work just as well in a loop.
well, i think that if you open a ofstream, everything else in the file is deleted, am i correct?
ill post the problem with new and delete on another thread in a little bit, my moms guna kill me

(i need to do hw)
Last edited by Llama : Oct 13th, 2007 at 5:00 pm.
Re: Finished my code, it compiles, but when i use build bersion, there is always an e
#9
Oct 13th, 2007
> >What stops this over stepping the array?
> huh?
What happens if the file has more than 5000 lines?
> but im trying to use new and delete for the array of line
Consider using a std::vector then, and save yourself a lot of confusion.
Besides, you should concentrate on getting this one to work rather than trying to rewrite it whilst it still has bugs.
> well, i think that if you open a ofstream, everything else in the file is deleted, am i correct?
Personally, I would create a temp file, then only replace the old file when I know the new file is created successfully.
If for some reason your program crashed soon after the
> huh?
What happens if the file has more than 5000 lines?
> but im trying to use new and delete for the array of line
Consider using a std::vector then, and save yourself a lot of confusion.
Besides, you should concentrate on getting this one to work rather than trying to rewrite it whilst it still has bugs.
> well, i think that if you open a ofstream, everything else in the file is deleted, am i correct?
Personally, I would create a temp file, then only replace the old file when I know the new file is created successfully.
If for some reason your program crashed soon after the
fout.open(File); you'd lose the lot. •
•
Join Date: Oct 2007
Posts: 16
Reputation:
Rep Power: 2
Solved Threads: 0
Re: Finished my code, it compiles, but when i use build bersion, there is always an e
#10
Oct 14th, 2007
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
access activation algos api blogger blogging blogs code combo dani daniweb data debugging development dreamweaver dropdownlist fortitude gdata google gpl hope html innovation key linux microsoft module net news openbsd product programming reuse rss serial source struggle tags trial-and-error victory vista web wysiwyg xml
- Dev-C++ - [Build Error] [main.o] Error 1 (C++)
- how to read a text file backwards? (C)
- error in my code (Java)
- Error 'not all code paths return a value' (C#)
- What is wrong? (C++)
- LNK2019 Error (C++)
- Program Compiles fine, but error upon Running (Java)
- How do you write a code which compiles in c but not in c++? (C++)
Other Threads in the C++ Forum
- Previous Thread: syntax error : missing ';' before '*'
- Next Thread: Can't start the program ..error



Linear Mode