Hello Community
i am using Linux (fedora) gcc compiler.
Normally i use Java but for the Interprocess communication part we got C.
My problem specifically is that when I read from a file with the fread() function
and save it in a char buff[somesize] I cant use printf() to display it in the console
so I used puts() to test if fread() did what it should.
When I use a named pipe to send the char array to another programm reading from that pipe
the function puts() and printf() in the programm reading the pipe display nothing in the console
I already wrote a programm where i use gets() to get a string from the console and send it and that worked flawlessly.
I ditched error handling and whatnot to keep the programm as simple as possible.
I have 2 terminals and start the programms seperatly.
It has to be some silly mistake or stream/buffer stuff I don't understand because for the life of it Google could not find anyone with the same problem
read and send:
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
int main(void) {
char buf[1024];
FILE *in;
int fd;
int ch = 0;
int count = 0;
in = fopen("start.c","rb");
fd = open("FIFO", O_WRONLY);
while (ch!=EOF) {
ch = fgetc(in);
++count;
}
rewind(in);
for(; ;) {
size_t n = fread (buf, 1, count, in);
buf[n] = '\0';
if(n<count)
break;
}
write(fd,buf,count);
colse(fd);
return 0;
}
get and display
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
int main() {
char buffer[1024];
int fd;
mkfifo("FIFO", 0777);
fd = open("FIFO", O_RDONLY);
read( fd, buffer, 300 );
puts(buffer);
printf("Ausgabe: %s \n",buffer);
close(fd);
unlink("FIFO");
return 0;
}
Thank you
notdoppler