typedef problems

i think the problem lies in the way i was using my typedef this is how it was explained to me and i would be very appreciative if someone would let me know what i'm doing wrong, also this is a partial program i'm not finished with it i just caught the problem and wanted to get it fixed before it got any worse
thanks


//Brandon Curry
/*this program will take an input file
and make a list of the words in that file
and if there is multiple uses of that word
the word it will be counted*/

#include <iostream.h>
#include <fstream>
#include <stdlib.h>
using namespace std;




class WordCount
{
public:
char word[31];
int count;

};

typedef WordCount WordEntryList[500];
void cleanupbegin (char word[31]);
void cleanupend (char word[31]);
void store(char word[31],int& count, int&size, WordEntryList[500]);


int main ()
{
WordEntryList list;
WordEntryList=0;

int numWordEntries;
char filename[41];
char wordFromFile[31];
char n;
char word[31];
ifstream inFile;

cout<< "Input file for word count:";
cin>> filename;
inFile.open(filename);

if( inFile.fail() )
{
cout<< "Error could not use this file";
exit(1);
}
else;

while (inFile.peek() != EOF)
{
inFile>>word;



cleanupbegin(word); //gets rid of punctuation
cleanupend(word); //gets rid of punctuation
void store(char word[31], int count, int size, WordEntryList); //store word
}

inFile.close();

}







//==========================================================================

void cleanupbegin (char word[31]) // cleans up the left side of the word

{
int n;
char x[31];
word=x;

if (x[0]!= ( x[0] >= 'A' && x[0]<='Z') || (x[0] >= 'a' && x[0] >= 'z'))
{
n=0;
while(word[n]!='\0')
{
word[n]=word[n+1];
n++;
}
}
else;



return;

}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

void cleanupend (char word[]) // cleans up the right side of the word
{
int done;
int y;
char x[31];
word=x;

done = 0;

y = strlen(word);

while (!done)
{
if ( x[y] != ( x[y] >='A' && x[y] <= 'Z') || ( x[y] >='a' && x[y] <='z'))
{
x[y] = '/0';
y--;
}
else
done = 1;
}
return;
}



//==============================================================================

void store(char word[],int count, int size, WordEntryList[500])
{
int found;
char wordFromFile[31];
int n;
int size;
size=0;
n=0;


while ( n<=size && !found)
{
if (strcmp(WordEntryList[n].word,word)==0)
found=1;
else;
n++;
}
if (found)
WordEntryList[n].count++;
else
{
strcpy(WordEntryList[size].word,word);
size++;
}
return;
}


You have not given us any errors.

However Line:
WordEntryList=0;

Should not compile, as you have not specified what to set to 0
Last edited on
all its sayin for errors is that

141 G:\c++ programs\wordcount.cpp expected primary-expression before '[' token

it says it more than once but its always right before where i have WordEntryList in the void store function

sry about that i'm just learning C++ and it's my first language. I just found this and thought it would be a big help to me
You can just cheat then :)

 
#define WordEntryList WordCount[500] 


Should achieve the same result.
Ok.

Changes to make that compile:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
void store(char word[],int count, int size, WordEntryList myList) 
// see I added a name for your variable WordEntryList 
{
int found;
char wordFromFile[31];
int n;
// int size; = Don't need this. It's a Parameter 
size=0;
n=0;


while ( n<=size && !found)
{
if (strcmp(myList[n].word,word)==0)
found=1;
else;
n++;
}
	if (found)
	  myList[n].count++;
else
{
strcpy(myList[size].word,word);
size++;
}
return;
}


myList is a variable of type WordEntryList. You cannot specify a type, without an instantiated variable.

x[y] = '\0';

This was '/0'; \0 represents NULL. Your typedef statement is fine.
Last edited on
thanks a lot man!!!!! that just saved me some major headaches
No worries :)
Topic archived. No new replies allowed.