So far I cant seem to even get my search right. I dont know exactly what to compare and what to use as my "size" of the array.
I am using the linear search algorithm for reference.
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
using namespace std;
struct word
{
char singleWord[21];
int count;
};
int main()
{
ifstream textDoc;
char text[21];
const int NUMBER=100;
word wordList[NUMBER];
int i=0;
int j=0;
char key;
textDoc.open("attempt.txt");
if (textDoc.fail())
{
cout<<"\nThe file didnt work "<<endl;
exit(1);
}
cout<<"\nThe file worked! "<<endl;
while(!textDoc.eof())
{
textDoc>>text;
strcpy(wordList[i].singleWord,text);
i++;
}
//test stuff delete this later**************************************
for(j=0; j<i; j++)
{
cout<< wordList[j].singleWord<<endl;
}
textDoc.close();
return 0;
}
int search(word wordList[],int count,char key[],word singleWord[])
{
int pos = 0;
int i;
while (pos < count && !strcmp(wordList[pos],singleWord[i]))
pos++;
if (pos == count)
pos = -1;
return pos;
}
can someone point me in the right direction for the search function?
any help would be much appreciated, thanks!
sidenote: I am using a text document called attempt.txt it is attatched
Attached File(s)
-
attempt.txt (26bytes)
Number of downloads: 31
This post has been edited by redrider11: 30 November 2010 - 02:53 PM

New Topic/Question
Reply



MultiQuote





|