I am having an issue with Code Blocks and Xcode on my Mac. Every time I run the code on Code Blocks I receive Segmentation Fault 11 and when I try on Xcode I receive Thread 1: exc_bad_access (code=1 address=0x0xffffffff0000000a). However, if I run this code on a PC via Code Blocks it runs. Does anybody know how to solve this so I can run the program on my Mac.
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
struct Book
{
string isbn;
string title;
string author;
double price;
string seller;
};
int main()
{
Book booklist[100];
ifstream infile;
ofstream outfile;
//int numBooks = 0;
int i=0;
char dummy;
outfile.open("readBooks.txt");
infile.open("usedBooks.txt");
if (infile.fail())
{
cout << "The file doesn't exist";
exit(-1);
}
else
{
//for (i=0; i<100; i++)
while (!infile.eof())
{
getline (infile, booklist[i].isbn);
getline (infile, booklist[i].title);
getline (infile, booklist[i].author);
infile >> booklist[i].price;
infile.get(dummy);
getline (infile, booklist[i].seller);
outfile << "ISBN: " << booklist[i].isbn << endl;
outfile << "Title: " << booklist[i].title << endl;
outfile << "Author: " << booklist[i].author << endl;
outfile << "Price: " << booklist[i].price << endl;
outfile << "Seller: " << booklist[i].seller << endl << endl;
i++;
}
}
}