Hi All,
I am having a problem with my program ceasing to work properly and shutting down rather ungracefully.
The routine appears to successfully do as intended up to the point where the function 'Get_Token()' returns
operation to the calling segment. At that point I get the following Windows error-message: ***********
FB Parser.exe has stopped working
A problem caused the program to stop working correctly.
Windows will close the program and notify you if a solution is
available.
Close program
*********************************************************************
The code sequence around my conception of the problem : -----------------------------------------------------------------------------------------------------------------------------------
*#include <fstream>
include <iostream>
include <stdio.h>
include <string>
using namespace std;
define Bad 0
define No 0
define OK 1
define Yes 1
bool Get_Token ( string, string, int );
/***********/
int main() {
bool done = No;
int h;
char ch[1], optr;
string instrg, outstrg, pin, pout;
/ ------------------------------ /
ifstream inf( "C:\Users\CF\InProgress\programming\FBTicTacToe\Trialtictac.bas" );
if ( !inf ) {
cout << "Input file could not be opened" << endl;
exit( 1 );
} // OK to use input file
ofstream outf( "C:\Users\CF\InProgress\programming\tokenized.txt",
ios::out | ios::app );
if ( !outf ) {
cout << "Output file could not be opened" << endl;
exit( 1 );
} // OK to use output file
h = 0;
do {
getline ( inf, instrg );
if ( inf.eof() ) { // reached end of file
done = true;
inf.close();
cout << "The last line of the file has been read-in" << endl;
}
.
.
.
.
/ ------------------------------/
else if (( instrg[h] == '\'' ) or // comment
( instrg[h] == '/' )) {
if ( Get_Token ( instrg, outstrg, h ) == OK ) outf << outstrg;
else goto problem;
}
.
.
.
.
return OK;
problem:
inf.close();
outf.close();
return Bad;
} / end of "main" ***********/
bool Get_Token ( string inlin, string token, int k ) {
int a = 0, b = k;
/ ----------------------------- /
try {
while (( inlin[b] != ' ' ) and ( inlin[b] != '\0' )) {
token[a] = inlin[b];
a = a + 1;
b = b + 1;
}
}
catch ( int ) {
cerr << "Procedure Get Token" << endl;
cerr << "problem: index in one of character arrays" << endl;
return Bad;
}
catch ( char ) {
cerr << "Procedure Get Token" << endl;
cerr << "problem: one of character arrays" << endl;
return Bad;
}
token[a] = '\0';
return OK;
} / end of function */
-------------------------------------------------------------------------------------------
I have done some check printing inside the function 'Get_Token()' with the expected results, right up to
the 'return OK' statement. There appears to be no response from the 'Try-Catch' sequencing, but since this
the first time I haved used this exception handling method, I am uncertain about my understanding of thee
facility. I have tried to do check-printing immediately after the return to the calling routine but got nothing.
The program died before it could print that it had returned.
I am using Windows 10 on a 64-bit architecture, version 5.11 of Dev-C++.
I simply do not understand what I have done wrong. Help from any direction will be greatly appreciated!!!!
Thanx in advance, greywolf38
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi All,
I am having a problem with my program ceasing to work properly and shutting down rather ungracefully.
The routine appears to successfully do as intended up to the point where the function 'Get_Token()' returns
operation to the calling segment. At that point I get the following Windows error-message:
***********
FB Parser.exe has stopped working
The code sequence around my conception of the problem :
-----------------------------------------------------------------------------------------------------------------------------------
*#include <fstream>
include <iostream>
include <stdio.h>
include <string>
using namespace std;
define Bad 0
define No 0
define OK 1
define Yes 1
bool Get_Token ( string, string, int );
/***********/
int main() {
bool done = No;
int h;
char ch[1], optr;
string instrg, outstrg, pin, pout;
/ ------------------------------ /
ifstream inf( "C:\Users\CF\InProgress\programming\FBTicTacToe\Trialtictac.bas" );
if ( !inf ) {
cout << "Input file could not be opened" << endl;
exit( 1 );
} // OK to use input file
ofstream outf( "C:\Users\CF\InProgress\programming\tokenized.txt",
ios::out | ios::app );
if ( !outf ) {
cout << "Output file could not be opened" << endl;
exit( 1 );
} // OK to use output file
h = 0;
do {
getline ( inf, instrg );
if ( inf.eof() ) { // reached end of file
done = true;
inf.close();
cout << "The last line of the file has been read-in" << endl;
}
.
.
.
.
/ ------------------------------/
else if (( instrg[h] == '\'' ) or // comment
( instrg[h] == '/' )) {
if ( Get_Token ( instrg, outstrg, h ) == OK ) outf << outstrg;
else goto problem;
}
.
.
.
.
return OK;
problem:
inf.close();
outf.close();
return Bad;
} / end of "main"
***********/
bool Get_Token ( string inlin, string token, int k ) {
int a = 0, b = k;
/ ----------------------------- /
try {
while (( inlin[b] != ' ' ) and ( inlin[b] != '\0' )) {
token[a] = inlin[b];
a = a + 1;
b = b + 1;
}
}
catch ( int ) {
cerr << "Procedure Get Token" << endl;
cerr << "problem: index in one of character arrays" << endl;
return Bad;
}
catch ( char ) {
cerr << "Procedure Get Token" << endl;
cerr << "problem: one of character arrays" << endl;
return Bad;
}
token[a] = '\0';
return OK;
} / end of function */
-------------------------------------------------------------------------------------------
I have done some check printing inside the function 'Get_Token()' with the expected results, right up to
the 'return OK' statement. There appears to be no response from the 'Try-Catch' sequencing, but since this
the first time I haved used this exception handling method, I am uncertain about my understanding of thee
facility. I have tried to do check-printing immediately after the return to the calling routine but got nothing.
The program died before it could print that it had returned.
I am using Windows 10 on a 64-bit architecture, version 5.11 of Dev-C++.
I simply do not understand what I have done wrong. Help from any direction will be greatly appreciated!!!!
Thanx in advance, greywolf38
У повсякденному житті 1 асоціюється з ,,так ,, і далі з ,,правда,, , ,,вірно,, та таке інше.
У C ++ функція "main" якщо вона нормально завершується, має видавати нуль.
Взагалі прийнято що функціі які видають нуль завершилися нормально, а одиниця найчастіше свідчить про помилку.
У вас define OK 1, а define Bad 0, тобто повинне бути навпаки.
Дужки начебто не симетричні .. Я ще подивлюся.
Потім.. Не сьогодні. Дві години за північ, я спати хочу.