It continuously prints the print statement without any value for token. What am i doing wrong.

char * get_word(FILE *file){
int i;
bool endoffile = true;
char *token =  malloc(WORD_SIZE*sizeof(char));
char c;
while((c = fgetc(file)) !=false){
    endoffile = false;
    if(c==' '||c=='\n'||c=='\t'){
        ungetc (c,file);
        break;  
    }else{
        token[i++]=ch;
    }
}
if(endoffile==false){
    token[i]='\0';
    printf("\n Word = %s",token);
    return token;

}else{
    return NULL;
}

}

0 Answers