Compile error on linux (a simple demo code on concept of pipe) -
so error when try compile code named pipe on linux
pipe.c: in function ‘main’: pipe.c:27:14: error: ‘amsg’ undeclared (first use in function) write(fd[1], amsg, strlen (amsg)); ^ pipe.c:27:14: note: each undeclared identifier reported once each function appears in pipe.c:30:41: error: expected ‘;’ before ‘:’ token printf("a got: %s , = %d\n", buf, i):}
this code:
#define size 1000 #include <stdio.h> #include <string.h> int main(void) { int fd[2]; char buf[size]; char *amsg = "nodea"; char *bmsg = "nodeb"; int = size; pipe(fd); if( fork() == 0) { sleep(1); read(fd[0], buf, 100); i++; printf("b got: %s , = %d\n", buf, i); write(fd[1], bmsg, strlen(bmsg)); // sleep(10); } else { write(fd[1], amsg, strlen (amsg)); wait(null); while((i = read(fd[0], buf, 100)) != 0) { printf("a got: %s , = %d\n", buf, i);} } }
how fix this? , thing confuse me sleep(1) means? mean 1 correct , if 1 go sleep process?
it seems simple syntax error. declared "char amsg " , later try refer variable amsg. have change m m .
Comments
Post a Comment