I'm writing a program that reads strings from a character buffer, and then prints a confirmation. The buffer I have initialized has a size of 50, but the number of strings inside the buffer isn't necessarily going to be 50. I am stuck on stopping the read once every string has been processed.
Code:
if((pid2=fork())==0){
int i, bytes; close(bc[1]);
for(i=0;i<sizeof(msg);i++){
if(strstr(msg, " ")!=NULL)
break;
else{
bytes = read(bc[0], msg, 3);
printf("C received %s from B\n", msg);
sleep(1);
}
}
close(bc[0]); exit(1);
I've tried looking for a white space, then breaking, but that hasn't worked. Any suggestions?