I'm in the process of making a program that parses words from a line, adding a word to a tree when it hits an nonalphanumeric character. Everything goes fine when there are no spaces in a line. However, when there are nonalphanumeric characters, the loop in question (beginning at the line commented in the code) halves in size!
Why does the loop halve?
Tree addin (char* filee, Tree tree)
{
int i;
FILE *fp;
fp = fopen(filee, "r");
char* hold2 = malloc(99);
int count=-1;
char* hold;
while ((hold=getLine(fp))!=NULL)
{
count=-1;
for (i=0; i<strlen(hold); i++) //The loop in question
{
count++;
if ((isalnum(hold[count])==0)&&(hold[count]!='\n'))
{
strncpy(hold2, hold, count);
hold2[count]='\0';
hold=strdup(&hold[count+1]);
count=-1;
tree = insertT(tree, hold2);
}
}
tree = insertT(tree, hold);
}
free(hold);
fclose(fp);
return tree;
}