So here is an updated code
here's MAIN
Code:
#include "inventory.txt"
#include "myfile.h"
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
std::ifstream infile("inventory.txt");
std::ofstream outfile("inventory.txt");
infile.open("inventory.txt");
outfile.open("inventory.txt");
Item myArray[Max];
read( myArray, "inventory.txt");
Print( myArray, 4 );
Print( myArray, 8 );
Print( myArray, 16 );
selectionSort( myArray, Max );
for (int x=0; x < Max; x++)
{
Print( myArray, x );
}
system("pause");
return 0;
}
here's my header
Code:
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
const int Max=100;
class Item
{
public:
string ID;
int sold;
int rem;
};
void read(Item Itemlist[], string filename)
{
std::ifstream infile(filename);
std::ofstream outfile(filename);
infile.open(filename);
outfile.open(filename);
for(int i=0; i<Max; i++)
{
infile >> Itemlist[i].ID;
cin.ignore(100, ' ');
infile >> Itemlist[i].sold;
cin.ignore(100, ' ');
infile >> Itemlist[i].rem;
}
infile.close();
outfile.close();
}
void Print(Item Itemlist[], int recNum )
{
cout << Itemlist[recNum].ID << " " << Itemlist[recNum].sold << " " << Itemlist[recNum].rem <<endl;
return;
}
void selectionSort(Item list[], int length )
{
//local vars
int smallestPos;
int temp;
// for every position in the array
for( int i=0; i<length; i++ )
{
// find the smallest element starting at that position
smallestPos = i;
for( int j=i+1; j<length; j++ )
{
if ( list[j].rem < list[smallestPos].rem )
{
// found a smaller one, remember it and keep going
smallestPos = j;
}
}
// see if we found something smaller than list[i]
if( list[i].rem > list[smallestPos].rem )
{
// we did find a smaller one, so swap with list[i]
temp = list[i].rem;
list[i] = list[smallestPos];
list[smallestPos].rem = temp;
}
}
// done sorting the array
}
Text file looks like this
Code:
619847GBE 641 998
418712IMB 107 867
Just don't know what i'm doing wrong
error C2059: syntax error : 'bad suffix on number' And i get this for every line in my text file