Okay, now i've read in my data into an array and passed it properly to my display function I'm trying to search each word in my array to determine if that word is already in the array, then i increment the number of UNIQUE words up by one, I'm using a linear search function:
1 2 3 4 5 6 7 8 9 10 11 12 13
int search (char array[], int size, char key[])
{
ifstream infile;
infile.open (array);
int pos = 0;
while (pos < size && infile.getline != key) //My issue is that I'm not sure
pos++; //how to indicate the particular
if (pos == size) //word i'm searching the array for
pos = -1;
return pos;
}
The idea here is; I have data from an external txt file stored in an array, I want to read in that txt file and as a word is read in, I search the array to see if the word is used more than once inside the array. If it is not, then I return a -1.
int search (char array[], int size, char key[]) // kbw: If array is a list of words, how are they represented?
{
ifstream infile;
infile.open (array); // kbw: I thought you said array was a list of words?int pos = 0;
while (pos < size && infile.getline != key) //My issue is that I'm not sure
pos++; //how to indicate the particular
if (pos == size) //word i'm searching the array for
pos = -1;
return pos;
}