prototype of function is something like
/*this program takes in input from a file...iterates thru line by line(or char by char depending on how you implement it)...looks for text only...and then prints out a list of each word(TEXT ONLY) and their frequencies. The way I thought to do it was to use a 2D array to store everything. But the memory for the array has to be dynamically allocated. That's where my problems are coming in.*/
void growArray(char *array, int x, int y);
int main()
{
int MAX_SIZE=300;
int x, y;
x=y=0;
char newChar;
char *array[128][128] = {0};
while ((newChar = cin.get()) != EOF){
if(y>=MAX_SIZE || x>=MAX_SIZE){
growArray(array, x, y);
MAX_SIZE+=MAX_SIZE; /*i fully realize if input line is 700 chars long i'm screwed. so help me. */
}
if(isspace(newChar) || ispunct(newChar)){
x=0; //goes back to element zero
y++; //but of the next row!
}
array[x][y]=newChar;
x++;
}
/*here's supposed to be the code to iterate thru 2D array, compare each one, SORT, and then print out the list. so it'll look like:
As 1
Bye 1
aloha 3
wassup 5
You get the idea.... help down for this part is appreciated too, especially the sorting. I have no idea how to bubble sort a 2D array */
return 0;
}
void growArray(char *array, int x, int y)
{
char *temp = new char[x][y]; /*err...don't quite remember what i put... */
for(int nCount=0; nCount < x; nCount++)
for(int mCount=0; mCount < y; mCount++)
temp[nCount][mCount] = array[nCount][mCount];
free(array ) /*this line was supposed to clean out old array. but i don't know how. help. */
array = temp;
}
/*So basically I got error saying i can't pass in char(*)[128] to function char *array or something like that. I'm doing this on Unix by the way. Any help is much much appreciated. Thanks.*/