I am filling a structure with words from a file. When the last word of the file is entered a null character is entered in the next structure member.
I am then passing the structure to a function with two pointers to the structures. I have a for loop that I want to be broken when one of the pointers points to the null in the structure member.
I am using an if statement and it does not seem to be working correctly.
I will post the code that I think is relevant.
THIS IS THE STRUCTURE AND THE FUNCTION THAT I AM PASSING IT INTO.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#define MAXWORDS 1000
typedef struct
{
char Words[88];
}UniqueWords;
void CompareWords(UniqueWords *pCompareWords, UniqueWords *pCompareWords2);
int main.....
THIS IS THE FUNCTION WITH THE POINTERS TO THE STRUCTURE THAT I AM PASSING IT INTO. THE IF STATEMENT IN GREEN IS WHERE I EXPECTED THE IF STATEMENT TO BREAK THE FOR LOOP.
I THOUGHT IT SHOULD BREAK WHEN THE POINTER HIT THE NULL OF THE STRUCTURE, BUT IT IS NOT.
Code:
void CompareWords(UniqueWords *pCompareWords, UniqueWords *pCompareWords2)
{
int i;
i=0;
while(CompareWords != '\0')
{
for(;;)
{
if(!strcmp(pCompareWords, pCompareWords2))
i++;
pCompareWords2++;
if(pCompareWords2 == '\0')
break;
}
}
pCompareWords++;
}
THANKS IN ADVANCE.