My problem statement is in such a way that I run a command and save the output of the command in a buffer. My while loop looks for a particular string in the output and if the string exists, runs the required function.
To end the while loop I have mentioned feof, in the while loop but the loop doesn't work!
Here is the snap of the code, I want to end the while loop in an optimized way!
FILE *fp = popen("ls","r");
char store[128];
while((fgets(store,sizeof store, fp)!=NULL) || (feof(fp))){
if(strcasestr(buffer,"abc")){
printf("\nSuccess");
some_other_function();
}
}
pclose(fp);
}