codeblocks stopped working, why??

I am doing a homework assignment for data structures involving ASCII font art and when i build and run the program it gives me a message saying my file has stopped working and is checking for a solution. Why is it doing this? Here is my code:

#include <iostream>
#include <fstream>
#include <cassert>
#include <vector>
#include <string>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <algorithm>

using namespace std;

// ======================================================================================

// Helper function to read the provided font from a file. The format
// of the font file is described in comments below. The width,
// height, and bitmap_letters variables are set by this function.
void ReadFont(const string &font_file,
int &width,
int &height,
vector<vector<string> > &bitmap_letters) {

// open the font file for reading
ifstream istr(font_file.c_str());
if (!istr) {
cerr << "ERROR: cannot open font file " << font_file << endl;
exit(0);
}

// read in the width & height for every character in the file
istr >> width >> height;
assert (width >= 1);
assert (height >= 1);

// Create a vector to store all 256 ASCII characters of the
// characters. Each character is represented as a vector of
// <height> strings that are each <width> wide. Initially the
// characters are unknown (represented with the '?' character).
bitmap_letters = vector<vector<string> >
( 256, vector<string> ( height, string(width, '?')));

// read in all the characters
// first is the ascii integer representation of the character
int ascii;
while (istr >> ascii) {
assert (ascii >= 0 && ascii < 256);
// next the character is printed in single quotes
char c;
istr >> c;
assert (c == '\'');
// use noskipws to make sure we can read the space character correctly
istr >> noskipws >> c;
// verify that the ascii code matches the character
assert (c == (char)ascii);
// switch back to skipws mode
istr >> skipws >> c;
assert (c == '\'');
// read in the letter
vector<string> bitmap;
string tmp;
for (int i = 0; i < height; i++) {
istr >> tmp;
assert ((int)tmp.size() == width);
// make sure the letter uses only '#' and '.' characters
for (unsigned int j = 0; j < tmp.size(); j++) {
assert (tmp[j] == '.' || tmp[j] == '#');
}
bitmap.push_back(tmp);
}
// overwrite the initially unknown letter in the vector
bitmap_letters[ascii] = bitmap;

}
}

// ======================================================================================

/* This function is designed to take the file "letter_file"
and split it up into individual characters, each of width
6. The code begins by importing the file. It then reads
through each line and separates characters into groups of 6.

Once the function has read through each line, it places each
group into the vector "letter_string".
*/

void PrintFont (const string &letter_file,
int &width,
int &height,
vector<vector<string> > &letter_string) {

ifstream ostr(letter_file.c_str());
if (!ostr) {
cerr << "ERROR: cannot open output file " << letter_file << endl;
exit(0);
}

string row; //used to store each line from the getline function
string hold_six; //hold_six will hold a group of 6 characters.
vector<string> b;
for (int i = 0; i < height; i++) {
getline( ostr, row); //Takes each line and stores it in the row string. *no way to use "ostr >> row" doesn't take white space*
for (unsigned int x = 0; x < (row.size()); x++) { //This for statement will replace
if ((row[x] == '@') || (row[x] == '*') || (row[x] == 'X') || (row[x] == '|')) { //each character with the correct
row[x] = '#'; //character, either a '#' or '.'
}
else if ((row[x] == ' ') || (row[x] == '_')) {
row[x] = '.';
}
}

for (unsigned int x = 0; x < (row.size()); x++) {
assert (row[x] == '.' || row[x] == '#'); //Make sure the row uses only '#' and '.' characters
}
for (unsigned int j = 0; j<((row.size())/(width + 1)); j++) {
hold_six = row.substr(j*7, (width)); //This is where the row is split into the groups.

if (i == 0){
b.push_back(hold_six);
letter_string.push_back(b);
}

else { //Otherwise the code will just put the string
letter_string[j].push_back(hold_six);

b.clear(); //once the group has been placed
hold_six.clear(); //vector & strings must be cleared for next group
}
row.clear();
}
}


// ======================================================================================

int main(int argc, char *argv[]) {
string display = "display"; //check to see if user wants to display
if (argv[1] == display) { //ASCII code or read it.
string font_file;
string text; //initialize variables to be used later.
font_file = argv[2];
text = argv[3];
char* foreground = argv[4];
char* background = argv[5];
int width; // Width and Height contain junk.
int height; // given values in Readfont
vector<vector<string> > bitmap_letters;
ReadFont(font_file, width, height, bitmap_letters); //Calls the function.

/* For each row the program will read through the
text string, and for each letter, it will find
the corresponding ASCII line. It will change
the background character to the one the user
input. and it will do the same for the foreground.

Afterward the program will output the line of ASCII
text and end the line. It will then move to the next line and repeat
until it is done.
*/
for (unsigned int l = 0; l < height; l++){
for (unsigned int pos = 0; pos < text.size(); pos++) {
for (unsigned int c = 0; c < bitmap_letters[text[pos]][l].size(); c++) {
if (bitmap_letters[text[pos]][l][c] == '.') {
bitmap_letters[text[pos]][l][c] = background[0];
}
else if (bitmap_letters[text[pos]][l][c] == '#') {
bitmap_letters[text[pos]][l][c] = foreground[0];
}
}
cout << bitmap_letters[text[pos]][l] << background ;
}
cout << endl;
}

}
string read = "read"; //if the user specifies read in the main argument
if (argv[1] == read) { //and if there are 3 arguments, read, the font file
string font_file; //and the ascii file the code will run
string letter_file;
font_file = argv[2];
letter_file = argv[3];
int width;
int height;
vector<vector<string> > bitmap_letters; // holds the full list of ascii characters
vector<vector<string> > letter_string; // holds the list of ascii characters to be converted
ReadFont(font_file, width, height, bitmap_letters);
PrintFont(letter_file, width, height, letter_string);

string text; //this string will be used for the output

/* The following for statements will compare each
character in the letter_string to every character
in the bitmap_letters until it finds a match.
If they are the same then it will add the character
to the text string. Once it has gone through all
of the characters the code will output the Text string.

*/
for (unsigned int i = 0; i < letter_string.size(); i++){
for (unsigned int x = 0; x < bitmap_letters.size(); x++) {
if (bitmap_letters[x] == letter_string[i]){
text.push_back(char(x));
break;
}
}
}
cout << text << endl;
}
return 0;
}


the spacing didn't copy right but it is all indented properly in codeblocks
Please select the code and press the <> button, then the code gets properly formatted and highlighted.
you are missing a brace before main. You use the arguments passed to main in your program, did you set code blocks to pass arguments into main? The first time I ran your program I hade the same problem you described above. Then I passed some arguments in and it ran fine.
Topic archived. No new replies allowed.