char - Reading word by word from text file in C -



char - Reading word by word from text file in C -

i new c. trying read words file contains lots of not alpha characters. input file looks %tom12%64tommy%^$$6 , want read tom first , set tom in info construction , read tommy , set in info construction in lowercase. have tried until now. other code works have manually sent parameters methods , there no errors. have tried read words file. word can of 100 characters max. can help me understand logic , perchance code.i lost.thank you!

void read(file *fp) { file *fp1 = fp; char word[100]; int x; int counter = 0; while ((x = fgetc(fp1)) != eof) { if (isalpha(x) == 0) { insert(&tree,word); counter = 0; } if (isalpha(x) != 0) { tolower(x); word[counter] = x; counter++; } } rewind(fp1); fclose(fp1); }

char *getword(file *fp){ char word[100]; int ch, i=0; while(eof!=(ch=fgetc(fp)) && !isalpha(ch)) ;//skip if(ch == eof) homecoming null; do{ word[i++] = tolower(ch); }while(eof!=(ch=fgetc(fp)) && isalpha(ch)); word[i]='\0'; homecoming strdup(word); } void read(file *fp){ char *word; while(word=getword(fp)){ insert(&tree, word); } //rewind(fp1); fclose(fp); }

c char fopen fgetc file-read

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -