I'm having a lot of trouble with one of my assignments. We are supposed to make a program that inputs text from a file, then separates the incoming data into tokens. And then place each one into a 2-dimensional array of C-strings. Then we are supposed to make a second copy of the array of tokens and use the bubble down function to sort it. Next we are supposed to output the two arrays in two side by side columns of tokens. So far this is what I have.
Code:
#include<cctype>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<stdio.h>
#include<fstream>
using namespace std;
void gettoken(ifstream& ReadFile, char thetoken, int& k);
void copyarray(char& temp, char thetoken, char tokencopy);
void outputarray(char tokencopy, char thetoken);
void welcomemsg();
void sortarray(char tokencopy, int& k);
void inputfilename(ifstream& ReadFile);
void farewell();
int main()
{
int k=0;
char temp[1000];
char tokencopy[500][500];
char thetoken[500][500];
ifstream ReadFile;
welcomemsg();
inputfilename(ReadFile);
gettoken(ReadFile, thetoken[500][500], k);
copyarray(temp[1000], tokencopy[500][500], thetoken[500][500]);
sortarray(tokencopy[500][500], k);
outputarray(tokencopy[500][500], thetoken[500][500]);
farewell();
return 0;
}
void welcomemsg()
{
cout << "Welcome to Michael's Parser." << endl;
}
void inputfilename(ifstream& ReadFile)
{
char pathname[50];
cout << "What is the name of the input file? " << endl;
cin >> pathname;
ReadFile.open(pathname);
}
void gettoken(ifstream& ReadFile, char thetoken, int& k)
{
char x;
ReadFile.get(x);
while(isalpha(x))
{
thetoken[k] = x;
k++;
ReadFile.get(x);
}
thetoken[k+1]='\0';
}
void copyarray(char& temp, char thetoken, char tokencopy)
{
int x=0;
int y=0;
while(isalpha(thetoken[y][0]))
{
temp = thetoken[y][x];
while(isalpha(temp));
{
temp = tokencopy[y][x];
x++;
temp = thetoken[y][x];
}
y++;
}
}
void sortarray(char tokencopy, int& k)
{
for(y=0; y < k; y++)
{
while(isalpha(tokencopy[0]))
{
while(tokencopy[y]<tokencopy[y+1])
{
swap(tokencopy[y], tokencopy[y+1]);
}
}
}
}
void outputarray(char tokencopy, char thetoken)
{
int y=0;
cout << setw(12) << right << fixed << "Original tokens";
cout << setw(12) << right << fixed << "Sorted tokens" << endl;
while(isalpha(thetoken[y]))
{
cout << thetoken[y] << " " << tokencopy[y];
}
}
void farewell()
{
cout << endl << "Thank you for using Michael's parser. Bye." << endl;
}
I know there are tons of errors in there but the one thing I am really having a problem with is when it compiles I get the error "subscript requires array or pointer type" multiple times. I understand it has something to do with reading in the information from the text file and copying it into the array but I just can't figure it out. Also I know the bubble down function is way off so any help with that also would be greatly appreciated, thanks.