(C++) terminate called after throwing an instance of 'std::bad_alloc' - c++

I keep getting an error of bad memory allocation. I've spent the whole night trying to find where I went wrong but I can't figure out what.
I've combed through every line but still nothing. Could it be that my program/laptop just isn't strong enough?
Any help would be extremely helpful. My head is ringing and I need some rest.
Here's my code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
// struct to store word + count combinations
struct wordItem{
string word;
int count;
};
void getStopWords(char *ignoreWordFileName, vector<string>& _vecIgnoreWords);
bool isCommonWord(string word, vector<string>& _vecIgnoreWords);
void printTopN(wordItem wordItemList[], int topN);
void doubleArray(wordItem wordItemList[], int size);
int getTotalNumberNonCommonWords(wordItem wordItemList[], int size, int wordCount);
const int STOPWORD_LIST_SIZE = 50;
// ./a.out 10 HW1-HungerGames_edit.txt HW1-ignoreWords.txt
int main(int argc, char* argv[]){
vector<string> vecIgnoreWords(STOPWORD_LIST_SIZE);
// verify we have the correct # of parameters, else throw error msg & return
if (argc != 4){
cout << "Usage: ";
cout << argv[0] << " <number of words> <filename.txt> <ignorefilename.txt>"<< endl;
return 0;
}
//Set vector with stop words
getStopWords(argv[3], vecIgnoreWords);
//initialize struct array
int aSize = 100;
wordItem *theStructArray = new wordItem[aSize];
int counter = 0;
int doubleCount = 0;
//read main txt file
ifstream inFile(argv[1]);
if(inFile.is_open()){
string line;
string theWord;
//extract words from file
while(getline(inFile, line)){
istringstream iss(line);
//extract and analyze word
while(iss >> theWord){
if(!(isCommonWord(theWord, vecIgnoreWords))){
bool inStructArray = false;
int inStructPosition;
//search for word in Struct array
while (inStructArray == false){
for(int i=0; i<aSize; i++){
if (theWord == theStructArray[i].word){
inStructArray = true;
inStructPosition = i;
}
}
break;
}
//if word is in struct array
if (inStructArray == true){
theStructArray[inStructPosition].count++;
}
//else if it isn't
else{
//create new wordItem and add into struct
wordItem newWord;
newWord.word = theWord;
newWord.count = 1;
theStructArray[counter+(100*doubleCount)] = newWord;
counter++;
}
//if struct array hits maximum amount of elements,
if (counter == (aSize-1)){
doubleArray(theStructArray, aSize);
counter = 0;
doubleCount++;
aSize +=100;
}
}
}
}
inFile.close();
}
//Bubble sort masterArray
int bI, bJ, flag = 1;
wordItem bTemp;
for(bI=1; (bI <= aSize && flag); bI++){
flag = 0;
for(bJ=0; bJ<aSize; bJ++){
if(theStructArray[bJ+1].count > theStructArray[bJ].count){
bTemp = theStructArray[bJ];
theStructArray[bJ] = theStructArray[bJ+1];
theStructArray[bJ+1] = bTemp;
flag = 1;
}
}
}
//Print topN words
printTopN(theStructArray, atoi(argv[1]));
//print others
cout << "#" << endl;
cout << "Array doubled: " << doubleCount << endl;
cout <<"#" << endl;
cout << "Unique non-common words: "<< (aSize-100+counter)<<endl;
cout << "#"<<endl;
cout <<"Total non-common words: "<< getTotalNumberNonCommonWords(theStructArray, aSize, counter)<<endl;
return 0;
}
void getStopWords(char *ignoreWordFileName, vector<string>& _vecIgnoreWords){
ifstream inFile(ignoreWordFileName);
if(inFile.is_open()){
int a = 0;
string line;
while(getline(inFile, line)){
_vecIgnoreWords.insert(_vecIgnoreWords.begin() + a, line);
}
inFile.close();
}
return;
}
bool isCommonWord(string word, vector<string>& _vecIgnoreWords){
for(int i=0; i<STOPWORD_LIST_SIZE; i++){
if(word == _vecIgnoreWords.at(i)){
return true;
}
}
return false;
}
void printTopN(wordItem wordItemList[], int topN){
cout << endl;
for(int i=0; i<topN; i++){
cout<< wordItemList[i].count << '-' << wordItemList[i].word << endl;
}
return;
}
void doubleArray(wordItem wordItemList[], int size){
wordItem *tempArray = new wordItem[size+100];
for(int i=0; i<size; i++){
tempArray[i] = wordItemList[i];
}
delete [] wordItemList;
wordItemList = tempArray;
}
int getTotalNumberNonCommonWords(wordItem wordItemList[], int size, int wordCount){
int total = 0;
for(int i=0; i<(size-100+wordCount); i++){
total+=wordItemList[i].count;
}
return total;
}

You are doing very bad things in void doubleArray(wordItem wordItemList[], int size)
you can call delete [] on the array if you pass an array, but you cannot change its value, so doubleArray(theStructArray, aSize); will cause theStructArray to be deleted but not assigned to the memory you allocated. You are just assigning the local variable in the function doubleArray
It is similar to:
void doubleit(int x)
{
x *= 2;
}
int y=3;
doubleit(y);
here x was momentarily doubled to 6, but y never changed.
you need to use references, or better make theStructArray a std::vector and be done with it.

Related

Tried making a hash table, can't map all keys, also program crashes

I have to make a program with a hash table that maps single random characters into the table. The program kind of works but sometimes it crashes, also it doesn't map every element. Some of them just won't get inside the table and there are always spare spaces in the table. I don't know what to do to solve these 2 problems. I used 3 versions of open adressing and each of them causes the same 2 problems. Sorry for my bad English. Thank you in advance.
Edited. Of course, I forgot about dynamic allocation. But the problem isn't solved.
#include <time.h>
#include <string>
#include <cstdlib>
using namespace std;
int Liniowo(int i, int proby, int rozmiar) // (open adressing, Linear probing)
{
if(i+proby<rozmiar)
return i+proby;
else
{
return -1;
}
}
int Kwadratowo(int i, int proby, int rozmiar) // (open adressing, Quadratic probing)
{
if (i+proby*proby<rozmiar)
return i+proby*proby;
else
{
return -1;
}
}
int Podwojnie(int i, int proby, int rozmiar, char klucz) // (open adressing, Double hashing)
{
if (i*(klucz*(701%klucz)-klucz%13)<rozmiar&&i*(klucz*(701%klucz)-klucz%13)>0)
return i*(klucz*(701%klucz)-klucz%13);
else
{
return -1;
}
}
int modularnie(char c,int rozmiar) // modular
{
return c%rozmiar;
}
void dodaj(char *tab,int max, char c) // add an element
{
int i=modularnie(c, max);
if (tab[i]== '\0')
tab[i]=c;
else
{
int u=0;
int h;
while (tab[i]!= '\0'&&h!=-1)
{
u++;
// h=Kwadratowo(i, u, max);
h=Podwojnie(i,u,max,c);
}
if (h!=-1)
tab[h]=c;
else
cout << "no niestety, nie udalo sie wstawic " <<endl; //"I couldn't map the element"
}
}
int wyszukaj(char *tab,int max, char c) // search an element
{
int i=modularnie(c, max);
int j=i;
if (tab[i]== '\0')
return -1;
while (tab[i]==c)
{
i=(i+1)%max;
if((i==j)||(tab[i]== '\0'))
return -1;
}
return i;
}
int usun(char *tab,int max, char c) // remove an element
{
int r,j,i=wyszukaj(tab,max,c);
j=i;
if (i==-1)
return -1;
tab[i]= '\0';
while (tab[(++i)%max]!= '\0')
{
i%=max;
r=modularnie(tab[i],max);
if (((i<r)&&(r<=j)) || ((r<=j)&&(j<i)) || ((j<i)&&(i<r)))
{
tab[j]=tab[i];
tab[i]= '\0';
j=i;
continue;
}
}
return 0;
}
int main()
{
srand( time( NULL ) );
int ile;
cout << "podaj wielkosc tablicy: "; //"Type the size of the table"
cin >> ile;
char* tab; // EDITED
tab=new char(ile);
for (int n=0; n<ile; n++)
{
tab[n]= '\0';
}
char e;
for (int i=0; i<ile; i++)
{
e='!'+rand()%127;
dodaj(tab, ile, e);
}
for(int j=0; j<ile; j++)
{
cout << j << ", " << tab[j] << endl;
}
return 0;
}

Error with strcoll (C++)

I want to sort a vector of strings into order alphabetically. I have coded thus far and I can not resolve the error for strcoll. Also, I am not allowed to use algorithm library. The error can be seen in the bubbub function where I am trying to bubble sort.
I have a few functions that should explain themselves with their names
#include <iostream>
#include <string.h>
#include <vector>
#include <stdio.h>
using namespace std;
inline void swap(string & a, string & b)
{
string c = b;
b = a;
a = c;
return;
}
void input_name(string&);
void sort_names(string&);
void repeat_pro(int&);
void sortArray(string, int);
void print_names(vector<string>& b_list);
void bubbub(vector<string> & b_list);
int main() {
vector<string> b_list;
string name;
int choice;
int count=0;
cout << "Welcome to the Business Sorting Program!" << endl;
do{
input_name(name);
b_list.push_back(name);
count++;
repeat_pro(choice);
bubbub(b_list);
cout<<"\n \n Your Businesses are:"<<endl;
for(int i=0; i < b_list.size() ; i++){
cout<<b_list[i]<<"\n";
}
cout << "\n\n";
}while(choice == 0);
cout << "Thanks for using this program"<<endl;
return 0;
}
void input_name(string &name){
cout << "Enter in the name of the business: ";
getline(cin, name);
}
void sort_names(string &name){
}
void repeat_pro(int &choice){
cout << "Do you want to enter in more names: ";
string answ;
cin>>answ;
cin.ignore(1000,'\n');
for (int x=0; x<answ.size(); x++){
answ[x] = tolower(answ[x]);
}
if (answ == "yes" || answ == "y"){
choice = 0;
}
else {
choice = 1;
}
}
void bubbub(vector<string> & b_list)
{
vector<string>::size_type loop = 0;
bool done = false;
while ((loop+1 < b_list.size()) && ! done)
{
done = true;
for (vector<string>::size_type count = 0;
count+1 != b_list.size(); count++)
{
string x;
string z;
x = b_list[count];
z= b_list[count+1];
if ( strcoll (x,z) < 0 )
{
swap( b_list[count], b_list[count+1] ); // swap
done = false;
}
}
loop++;
}
return;
}
I fixed it by converting my string into a list of chars. then compared them and swapped the vector based on the results. Thanks for the help guys
void bubbub(vector<string> & b_list)
{
vector<string>::size_type loop = 0;
bool done = false;
while ((loop+1 < b_list.size()) && ! done)
{
done = true;
for (vector<string>::size_type count = 0;
count+1 != b_list.size(); count++)
{
string x;
string z;
char array[50];
char array2[50];
x = b_list[count];
z= b_list[count+1];
strncpy(array, x.c_str(), sizeof(x));
strncpy(array2, z.c_str(), sizeof(z));
if ( strcoll (array,array2) > 0 )
{
swap(b_list[count+1], b_list[count] ); // swap
done = false;
}
}
loop++;
}
return;
}
You can use std::string::compare instead of strcoll
#include <iostream>
#include <vector>
#include <stdio.h>
#include <cstring>
using namespace std;
inline void swap(string & a, string & b)
{
string c = b;
b = a;
a = c;
return;
}
void input_name(string&);
void sort_names(string&);
void repeat_pro(int&);
void sortArray(string, int);
void print_names(vector<string>& b_list);
void bubbub(vector<string> & b_list);
int main() {
vector<string> b_list;
string name;
int choice;
int count=0;
cout << "Welcome to the Business Sorting Program!" << endl;
do{
input_name(name);
b_list.push_back(name);
count++;
repeat_pro(choice);
bubbub(b_list);
cout<<"\n \n Your Businesses are:"<<endl;
for(int i=0; i < b_list.size() ; i++){
cout<<b_list[i]<<"\n";
}
cout << "\n\n";
}while(choice == 0);
cout << "Thanks for using this program"<<endl;
return 0;
}
void input_name(string &name){
cout << "Enter in the name of the business: ";
getline(cin, name);
}
void sort_names(string &name){
}
void repeat_pro(int &choice){
cout << "Do you want to enter in more names: ";
string answ;
cin>>answ;
cin.ignore(1000,'\n');
for (int x=0; x<answ.size(); x++){
answ[x] = tolower(answ[x]);
}
if (answ == "yes" || answ == "y"){
choice = 0;
}
else {
choice = 1;
}
}
void bubbub(vector<string> & b_list)
{
vector<string>::size_type loop = 0;
bool done = false;
while ((loop+1 < b_list.size()) && ! done)
{
done = true;
for (vector<string>::size_type count = 0;
count+1 != b_list.size(); count++)
{
string x;
string z;
x = b_list[count];
z = b_list[count+1];
if (z.compare(x) != 0 )
{
swap( b_list[count], b_list[count+1] ); // swap
done = false;
}
}
loop++;
}
return;
}
Output
Welcome to the Business Sorting Program!
Enter in the name of the business: hello
Do you want to enter in more names: yes
Your Businesses are:
hello
Enter in the name of the business: apple
Do you want to enter in more names: no
Your Businesses are:
apple
hello
Thanks for using this program
Program ended with exit code: 0

How can I check if array is full and double/half the size of it?

This program reads information from a text file, stores it in an array, and performs one of 3 functions. I need to be able to check if the array is full and double the size if it is or half the size if their is a deletion 1/4 of the size of the array. Tried to be brief so if you need more information, let me know.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct info{
char letter;
string SSN;
string firstName;
string lastName;
};
void insertion(int &count, int &validInsertationCount, string &SSN, char &letter, string &firstName, string &lastName, info *list);
void deletion(int &count, int &validDeletionCount, string &SSN, char &letter, string &firstName, string &lastName, info *list);
void retrieval(int &count, int &validRetrievalCount, string &SSN, string &firstName, string &lastName, info *list);
int main(int argc, char* argv[]){
int arraySize = 1000;
struct info list[1000];
fstream input(argv[1]);
int count = 0;
int validInsertationCount = 0;
int validDeletionCount = 0;
int validRetrievalCount = 0;
while(!input.eof()){
input >> list[count].letter >> list[count].SSN >> list[count].firstName >> list[count].lastName;
if(list[count].letter == 'i'){
insertion(count, validInsertationCount, list[count].SSN, list[count].letter, list[count].firstName, list[count].lastName, list);
}
else if(list[count].letter == 'd'){
deletion(count, validDeletionCount, list[count].SSN, list[count].letter, list[count].firstName, list[count].lastName, list);
}
else if(list[count].letter == 'r'){
retrieval(count, validRetrievalCount, list[count].SSN, list[count].firstName, list[count].lastName, list);
}
count++;
}
input.close();
int numberOfItems = validInsertationCount - validDeletionCount;
cout << "The Number of Valid Insertation: " << validInsertationCount << endl;
cout << "The Number of Valid Deletion: " << validDeletionCount << endl;
cout << "The Number of Valid Retrieval: " << validRetrievalCount << endl;
cout << "Item Numbers in the array: " << numberOfItems << endl;
cout << "Array Size is: " << arraySize << endl;
//cout << "Time Elapsed: " << <<endl;
}
void insertion(int &count, int &validInsertationCount, string &SSN, char &letter, string &firstName, string &lastName, info *list){
for(int i = 0; i < count; i++){
if(SSN == list[i].SSN && list[i].letter == 'i'){
for(int k = i; k < count; k++){
list[k].SSN = list[k+1].SSN;
list[k].letter = list[k+1].letter;
list[k].firstName = list[k+1].firstName;
list[k].lastName = list[k+1].lastName;
}
count--;
return;
}
}
validInsertationCount++;
return;
}
void deletion(int &count, int &validDeletionCount, string &SSN, char &letter, string &firstName, string &lastName, info *list){
for(int i = 0; i < count; i++){
if(SSN == list[i].SSN && firstName == list[i].firstName && lastName == list[i].lastName){
for(int k = i; k < count; k++){
list[k].SSN = list[k+1].SSN;
list[k].letter = list[k+1].letter;
list[k].firstName = list[k+1].firstName;
list[k].lastName = list[k+1].lastName;
}
count--;
validDeletionCount++;
return;
}
}
}
void retrieval(int &count, int &validRetrievalCount, string &SSN, string &firstName, string &lastName, info *list){
for(int i = 0; i < count; i++){
if(SSN == list[i].SSN && firstName == list[i].firstName && lastName == list[i].lastName){
validRetrievalCount++;
}
}
return;
}
You can't simply resize a statically allocated array so you'll want to either use std::vector or malloc/new to allocate a dynamic array. However in that case you can't determine the size of the array using sizeof(). So you either keep a size variable or use a "delimiter" value in order to pinpoint the end of the array.

Program crashes due to undefined behavior

So I'm writing a program that creates a library for a collection of CDs and displays them. My program compiles but crashes whenever I write an array of pointers to songs from a file into structs contained within an array shown here:
//Get song array
for (int a = 0; a < num_songs; a++)
{
getline (infile, line);
sub = line.c_str();
word = createString(sub);
length = substr(word, -1, 5);
title = substr(word, 5, strlen(sub));
cd->song_array[a] = createSong(title,length);
destroyString(word);
}
I think it's due to undefined behavior, here's the .cpp file that this is happening in.
#include <iostream>
#include "CDs.h"
#include "CD.h"
#include <fstream>
#include <string>
#include <cstring>
using namespace std;
//Creates a collection of CDs
CDs* createCDs(const char* file_name)
{
//Declare variables and allocate memory
int max_cds = 50;
CDs* collection = new CDs;
collection->max_cds = max_cds;
CD** cd_array = new CD*[max_cds];
int num;
int sentinel = 0;
String* word;
string line;
CD* cd;
const char* sub;
String* length;
String* title;
//Open .txt file
ifstream infile;
infile.open(file_name);
if (infile.is_open())
{
while (infile.good())
{
for (int i = 0; i < max_cds; i++)
{
//Get the artist from .txt file
cd = cd_array[i];
getline (infile, line);
sub = line.c_str();
word = createString(sub); //Create string from infile line
cd->artist = word;
destroyString(word);
//Get the Title of the album from file
getline (infile, line);
sub = line.c_str();
word = createString(sub);
cd->title = word;
destroyString(word);
//Get the Year of the album from file
infile >> num;
cd->year = num;
//Get the Rating
infile >> num;
cd->rating = num;
//Get number of tracks
int num_songs;
infile >> cd->num_tracks;
//Get song array
for (int a = 0; a < num_songs; a++)
{
getline (infile, line);
sub = line.c_str();
word = createString(sub);
cout << "SHIT" << endl;
length = substr(word, -1, 5);
title = substr(word, 5, strlen(sub));
cd->song_array[a] = createSong(title,length);
destroyString(word);
}
cd_array[i] = cd;
sentinel++;
}
}
}
else
{
cout << "file did not open";
}
collection->cd_array = cd_array;
collection->num_cds = sentinel;
collection->max_cds = max_cds;
return collection;
}
I have no idea what to do to make this run, If someone could help that would be amazing.
edit - I didn't give the .cpp that is included and has some of the functions used
#include <iostream>
#include <cstring>
#include "String.h"
using namespace std;
//Function that creates a string
String* createString(const char* char_array)
{
//Allocate memory for a pointer to String struct
//String* string;
String* string = new String;
//Write the char_array to String struct
int length = strlen(char_array);
char array[30];
for (int i = 0; i <= length; i++)
{
array[i] = char_array[i];
string->array[i] = array[i];
}
return string;
}
//Function that displays the string
void displayString(String* str)
{
for (int i = 0; i < strlen(str->array); i++)
{
cout << str->array[i];
}
cout << endl;
}
//Function that destroys the string
void destroyString(String* str)
{
delete str;
str = NULL;
}
int find(String* str, char delimiter, int start)
{
for (int i = start; i <= strlen(str->array); i++)
{
if (str->array[i] == delimiter)
{
return i;
}
}
cout << "No occurences of delimiter were found" << endl;
return -1;
}
String* substr(String* str, int start, int end)
{
String* new_str = new String;
int count = 0;
for (int i = start + 1; i < end - 1; i++)
{
new_str->array[count] = str->array[i];
count++;
}
return new_str;
}
void compare(String* str1, String* str2)
{
if (str1->array < str2->array)
{
cout << str1->array << " is less than " << str2->array << endl;
}
if (str1 > str2)
{
cout << str2->array <<" is less than " << str1->array << endl;
}
if (str1 == str2)
{
cout << "The strings are equal" << endl;
}
}
You never allocate memory for the effective CD. You just allocate an array of pointers to CDs (cd_array). This means you have an array of pointers, pointing to unkown memory locations.
The best way to ensure no such bad access is possible, is to not dynamically allocate memory. Just use CD cd_array[max_cds] and work with that. (Use call by reference, if you need to pass this to a function.)
You need to add the following lines:
//Get the artist from .txt file
cd_array[i] = new CD;
cd = cd_array[i];
.....
You should de-allocate the memory once finished using them
for(...)
delete cd_array[i];
delete []cd_array;

Queue Simulation problem

My program is to print the queue of information from a file but i have problem with my following code. When i run the program it keep loop. I cant figure out the problem. Any help?
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <queue>
#include <list>
using namespace std;
void simulation(ifstream &infile);
void processArrival(int *newEvent, ifstream &inFile, list<int> eventList,queue<int> printQueue);
void processDeparture(int *newEvent, list<int> eventList,queue<int> printQueue);
string name[100];
int timeAccepted[100];
int fileSize[100];
int i = 1;
int j = 1;
int currentTime;
bool checker = true;
int main(void)
{
ifstream inFile;
string fileName;
int i = 0;
inFile.open("123.txt", ios::in);
simulation(inFile);
/*while(inFile.peek() != EOF )
{
inFile>>name[i]>>timeAccepted[i]>>fileSize[i];
i++;
}
for(int s = 0; s < i; s++)
{
cout << name[s] << timeAccepted[s] << fileSize[s] <<endl;
}*/
return 0;
}
void simulation(ifstream &inFile)
{
queue<int> printQueue;
list<int> eventList;
int *newEvent;
while(inFile.peek() != '\n')
{
inFile>>name[0]>>timeAccepted[0]>>fileSize[0];
}
eventList.push_front(timeAccepted[0]);
int checkEmpty = eventList.empty();
newEvent = &eventList.front();
while(checkEmpty ==0)
{
newEvent = &eventList.front();
if(checker)
{
processArrival(newEvent, inFile, eventList, printQueue);
}
else
{
processDeparture(newEvent, eventList, printQueue);
}
checkEmpty = eventList.empty();
}
}
void processArrival(int *newEvent, ifstream &inFile, list<int> eventList,queue<int> printQueue)
{
int atFront=0;
atFront = printQueue.empty();
cout << atFront <<endl;
printQueue.push(*newEvent);
cout << printQueue.front() <<endl;
eventList.remove(*newEvent);
int temp;
if(atFront==1)
{
currentTime = *newEvent + fileSize[0];
cout << name[0] << " ## " << *newEvent << " ## " << currentTime << endl;
eventList.push_back(currentTime);
}
checker = false;
if(inFile.peek() != EOF )
{
inFile>>name[i]>>timeAccepted[i]>>fileSize[i];
eventList.push_back( timeAccepted[i] );
i++;
checker = false;
if(eventList.back() <= eventList.front())
{
temp = eventList.back();
eventList.back() = eventList.front();
eventList.front() = temp;
checker = true;
}
}
}
void processDeparture(int *newEvent, list<int> eventList,queue<int> printQueue)
{
printQueue.pop();
eventList.pop_front();
int checkEmpty = 1;
checkEmpty = printQueue.empty();
int temp;
if(checkEmpty ==0)
{
currentTime = *newEvent + fileSize[j];
cout << name[j] << " " << *newEvent << " " << currentTime << endl;
eventList.push_back(currentTime);
checker = true;
if(eventList.back() < eventList.front())
{
temp = eventList.back();
eventList.back() = eventList.front();
eventList.front() = temp;
checker = false;
}
j++;
}
}
Your processArrival and processDeparture functions are taking their eventList and printQueue arguments by value. This means that when you call them, for example in this line:
processArrival(newEvent, inFile, eventList, printQueue);
Copies of eventList and printQueue are made and passed into the processArrival function. The processArrival function then operates on those copies, and the original data is never modified. In particular, this means that the original eventList will never have any items removed from it, so it will never be empty -- it will just keep trying to process the first event over and over again.
The solution is to pass these parameters by reference. i.e. change the definition of processArrival to
void processArrival(int *newEvent, ifstream &inFile, list<int>& eventList, queue<int>& printQueue)
Note the & characters that I have inserted before eventList and printQueue. These cause references to the original data, rather than copies of the original data, to be passed into the processArival function. This means that processArrival will operate directly on the original data as you intend it to. Don't forget to make the corresponding change to processDeparture as well.