Saturday 17 August 2013

Branching issue in C program

Branching issue in C program

My C program needs to skip rest of the code if particular event occurs. I
have used continue for that but there is some issue. I am not sure issue
is due to that only or something different but it's something logic
mistake.
I am sending word to BoyerMoore_positive(ch[i], strlen(ch[i]) ); function
to verify whether it exist in particular word list or not. If exist then
increment count values.
for skp = BoyerMoore_skip(ch[i], strlen(ch[i]) ); if word is present in
this function then I want to skip rest of the code and continue with next
word. So I incremented the i.
It checks "he is the you she am" this list. But when word is present in
this list and come back after performing actions in the function it does
not proceed to next word though I have incremented i. It keep looping in
BoyerMoore_skip(ch[i], strlen(ch[i]) ); for some times and then stops
without processing next word.
I know this is very specific issue to my program but any kinda help is
highly appreciable. I may making some silly mistake.
code:
while ((NULL != word) && (50 > i)) {
ch[i] = strdup(word);
//printf("%s n", ch[i]);
skp = BoyerMoore_skip(ch[i], strlen(ch[i]) );
// printf("skip is %s \n",skp);
if(skp != NULL)
{
i++;
printf("in\n");
continue;
}
// I tried with keeping i++ and continue in seperate if(skp != NULL) but
same result.
printf("\n hi2 \n");
str = BoyerMoore_positive(ch[i], strlen(ch[i]) );
str2= BoyerMoore_negative(ch[i], strlen(ch[i]) );
printf("Str is %s \n",str2);
if (str == NULL)
t++;
else {
printf("%s \n", ch[i]);
// puts("true");
pcount += 1;
printf("Positive count is: %d \n",pcount);
}
if(str2== NULL)
q++;
else {
printf("%s \n", ch[i]);
// puts("true");
ncount += 1;
printf("Nagative count is: %d \n",ncount);
}
i++;
word = strtok(NULL, " ");
if(str==NULL && str==NULL and skp !=NULL)
{
pcount=0;
ncount=0;
}
}

No comments:

Post a Comment