I'm doing program and in this program i have two processes, server and client. Server have to read string from input and then write into FIFO file. Client have to read strings from FIFO file and then wrote into .txt file. This are only function responsible for server and client. File FIFO and fork'ing is doing in main function.
void server(void)
{
FILE *fp1, *fp2;
char string[100];
while(1)
{
fp1 = fopen("FIFO1", "w");
fprintf(stdout, "Type string: ");
scanf("%s", string);
fputs(string, fp1);
fclose(fp1);
sleep(1);
}
}
void client(void)
{
FILE *fp,*fp1;
char string[100];
while(1)
{
fp = fopen("FIFO1", "r");
fgets(string, 100, fp);
fclose(fp);
fp1 = fopen("file.txt", "a");
fprintf(fp1,"%d_file: I get: %s\n", getpid(), string);
fclose(fp1);
}
}
And my problem is when i type a string like "stack overflow", when i have two word, in my file.txt
i get to lines:
8965_file: I get: stack
8965_file: I get: overflow
Is there any way to write this in one line ? Like this:
8965_file: I get: stack overflow