Home > Back-end >  Error: structure has no member named ` d_type 'how to solve?
Error: structure has no member named ` d_type 'how to solve?

Time:10-09

# include
# include
# include
# include
H # include
# include
# include

# define TYPE struct words
# define LEN sizeof (struct words)
TYPE * create_list (FILE *, char []);
Void print_list (TYPE *);
Void classification (TYPE * TYPE *);

Struct words {
Char word [5000];//the word name
Int count;//the amount of this word appears in this file
Char classify [10].//the class of this word
Double pHam.//possibility of class ham for this word
Double pSpam;//possibility of class spam
Struct words * next;//point to the next word
};

//int TotCount=0;
//int DifCount=1;
Int numSpamWords=0;//all distinct words of class spam
Int numHamWords=0;//all distinct words of class ham
Char finalClass [5].//final class of the test file
Int numHamFile=0;//the number of ham files;
Int numSpamFile=0;//the number of spam files



Int main (int arg c, char * argv [])

{
Temp TYPE * head=NULL, * and * last, * head1;
The FILE * fp, * fp1;
DIR * dirptr=NULL;
int count=0;//count that the amount of files
Struct dirent * entry;
TestFile char trainDir [300], [300], trainFile [300].

Strcpy (trainDir, argv [1]);
Strcpy (testFile, argv [2]);

If ((dirptr=opendir (trainDir))==NULL)
{
Printf (" There are no this dir ");
return 1;
}
The else
{
While ((entry=readdir (dirptr))!=NULL)
{
If ((entry -> d_type)==8)
{
Strcpy (trainFile trainDir);
Strcat (trainFile, "/");
Strcat (trainFile, entry -> d_name);
If ((fp=fopen (trainFile, "r"))==NULL)
{
Printf (" Can 't open this file \ n ");
The exit (1);
}
If (STRSTR (entry -> d_name, "ham"))
{
Temp=create_list (fp, "ham");
NumHamFile++;
}
If (STRSTR (entry -> d_name, "spam"))
{
Temp=create_list (fp, "spam");
NumSpamFile++;
}
The fclose (fp);
count++;
If (count==1)
The head=temp;
The else
Last -> next=temp;
While ((temp -> next)!=NULL)
temp=temp->next;
The last=temp;
}
}
Closedir (dirptr);
}

If ((fp1=fopen (testFile, "r"))==NULL)
{
Printf (" Can not open this test file \ n ");
The exit (1);
}
Head1=create_list (fp1, "unknow");
The fclose (fp1);
//print_list (head4);

Classification (head, head1);//the classify the test file

Printf (" % s \ n ", finalClass);
}


Fp TYPE * create_list (FILE * and char classify [10])
{

Last TYPE * in * and * head=NULL, * temp;
char ch;
Char CRH [5000].
int n=0;
/* int TotCount=0;
Int DifCount=1; */

Ch=fgetc (fp);//get the first char in the file
While (ch==' ')
Ch=fgetc (fp);

while(ch!=(EOF)

{
//if the 'ch' is', jump it, if the 'ch' is EOF, exit this loop
Int I=0;

If (EOF) ch==
break;
//create a node
If ((=in malloc (LEN))==NULL)
{
Printf (" out of memory! \n");
exit(0);
}
//get words from the file
While (((ch)>='a' && (ch) <='z') | | ((ch)>='a' && (ch) <='z') | | (ch=='-'))
//while ((ch!=' ') && (ch!=(EOF) && (ch!='\ 0'))
{
CRH [I]=ch;
i++;
Ch=fgetc (fp);
}
Ch=fgetc (fp);
While (ch==' ')
Ch=fgetc (fp);
CRH [I]='\ 0';
/* TotCount++; */
n++;
//put the information to the node
Strcpy (-> in word, CRH);
The in -> count=1;
The in -> next=NULL;
Strcpy (-> in the classify, the classify);

If (STRCMP (-> in word, "\ 0"))
{
//create the head node in this list
If (n==1)
{
The head=in;
The last=in;
}
The else
{
Temp=head;
While ((temp!=NULL) && STRCMP (-> in word, temp -> word))
temp=temp->next;
If (temp==NULL)
{
Last -> next=in;
The last=in;
//DifCount++;
}
The else
Temp -> count=temp -> count + 1;
}
//add the number of spam words or ham
If (the classify=="ham")
NumHamWords++;
Else if (the classify=="spam")
NumSpamWords++;
}
}
return head;
}


Void print_list (TYPE * head)
{
While (the head!=NULL)
{
Printf (" % s % d % s \ n ", the head -> word, head -> count, head -> the classify);
The head=head -> next;
}
}

//the function is the for the classify each word in the test file, the first parameter is the head of training
//the list and the second parameter is the head of the test list
Void classification (TYPE * head1, TYPE * head2)
{
P1 TYPE * and * (p2);
Int nHam nSpam;//count the number of one word which is classified by ham or spam
Double pHamFile=0, pSpamFile=0;//count the possibility of this file to be ham or spam
Double pHamWords=0, pSpamWords=0;//the sum Numbers of all the ham or spam words in testing the file
P1=head1;
The p2=head2;
While (p2!=NULL)
{
NHam=0;
NSpam=0;
While (p1! nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related