I really went wrong with this one.
I have a .txt file with the contents:
1, 2, zz
1, 9, ccc
2, 3, lll
2, 13, aaaaa
3, 3, mmm
3, 11, oo
Just so you know the info in the file represents LINE#, COLUM#, text. This .txt file is also the output from another part of this program...but that part works.
Anyways I will be sorting the data by the alpha characters. I have been looking at example and it seems that I must first put this data into an array so that I can use pointers and then use the qsort() function. I am however stuck as to how to put the data into a 2D array. My code is messed up, what am I doing wrong (besides everything)?
Code:using namespace std; int main() { ifstream inData; ofstream outData; char ch; char lineData[BUFSIZ][50]; int index6 = 0; int lineCount = 1; inData.open("text.txt"); if(!inData) cout << "ERROR in opening " << "text.txt" << endl; else if(inData) { cout << "Opening file: " << "text.txt" << endl << endl; ch = inData.get(); while(ch != EOF) { if(ch == '\n') { lineCount++; index6 = 0; } lineData[lineCount][index6] = ch; ch = inData.get(); index6++; cout << lineData << endl; } outData.close(); } return 0; }



LinkBack URL
About LinkBacks


