i'm in process of making program parses words line, adding word tree when hits nonalphanumeric character. goes fine when there no spaces in line. however, when there nonalphanumeric characters, loop in question (beginning @ line commented in code) halves in size!
why 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; (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; }
when find non-alphanumeric character, program moves hold
point remainder of string, doesn't reset i
. means continue iterating new hold
pointer, partway original one, plus whatever i
happened @ time. doing presumably at least skips bunch of characters, , possibly makes start operating on memory outside of string, definitely bad news.
Comments
Post a Comment