I have been getting hands on recursive technique using C , here the problem I am facing -
bool FetchInputFromFile(int file_dis ){
// file_dis is the file descriptor which I have used in main with `open` sys call
char ch; //I want to read char wise
size_t ch_size =sizeof(ch );
char temp[30];
size_t index =0;
size_t numread;
//memset(temp, 0, 30 );
numread =read(file_dis, &ch, ch_size );
if(ch == ' ' ){
temp[index ] = '\0';
index =0;
InsertInList(temp ); //calling function with temp
}else temp[index++] = ch;
//1//
//base case and recursive call
if(numread ==0 ) return true;
else if(numread == -1 )return false;
else FetchInputFromFile(file_dis );
}
if I put printf("%s", temp );
where I have mentioned //1//
above then the output is coming fine but if I call function over there , its going character wise.
What I am trying to do is I am reading file with open
sys call and I am passing the file to the above function and trying to read char by char.But, it's not happening.
Please help me how I can call function where the output goes word by word.
THANKS!!!!