User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Oct 2007
Posts: 16
Reputation: Llama is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Llama Llama is offline Offline
Newbie Poster

Question 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:

#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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2007
Location: Home
Posts: 2,451
Reputation: zandiago is on a distinguished road 
Rep Power: 6
Solved Threads: 24
Featured Poster
zandiago's Avatar
zandiago zandiago is offline Offline
Nearly a Posting Maven

Re: Finished my code, it compiles, but when i use build bersion, there is always an error

  #2  
Oct 12th, 2007
what "problem" does it say it's having? Copy the error log and post it here so that we can see it.
Reply With Quote  
Join Date: Oct 2007
Posts: 16
Reputation: Llama is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Llama Llama is offline Offline
Newbie Poster

Re: Finished my code, it compiles, but when i use build bersion, there is always an e

  #3  
Oct 12th, 2007
no, you dont understand

it compiles.

but when i run the build version, it either can open the file, or a window pops up saying


SRL 3.81 to SRL 4.exe has encountered a problem and needs to close. We are sorry for the inconvenience.
Reply With Quote  
Join Date: Sep 2004
Posts: 6,515
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 489
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

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.
I'm here to prove you wrong.
Reply With Quote  
Join Date: Oct 2007
Posts: 16
Reputation: Llama is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Llama Llama is offline Offline
Newbie Poster

Re: Finished my code, it compiles, but when i use build bersion, there is always an e

  #5  
Oct 12th, 2007
i dont get error when i run it in debug mode...
Reply With Quote  
Join Date: Sep 2004
Posts: 6,515
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 489
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Finished my code, it compiles, but when i use build bersion, there is always an e

  #6  
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'm here to prove you wrong.
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
banned

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.
Reply With Quote  
Join Date: Oct 2007
Posts: 16
Reputation: Llama is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Llama Llama is offline Offline
Newbie Poster

Re: Finished my code, it compiles, but when i use build bersion, there is always an e

  #8  
Oct 13th, 2007
Originally Posted by Narue View Post
>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

Originally Posted by Salem View Post
> 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.
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
banned

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 fout.open(File); you'd lose the lot.
Reply With Quote  
Join Date: Oct 2007
Posts: 16
Reputation: Llama is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Llama Llama is offline Offline
Newbie Poster

Re: Finished my code, it compiles, but when i use build bersion, there is always an e

  #10  
Oct 14th, 2007
how do i use vectors?

temp file? i would run into the same problem, wouldn't i?
Last edited by Llama : Oct 14th, 2007 at 2:11 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 4:43 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC