שאלה קטנה על קוד C
היי, אני לומד קצת עבודה עם processes ו pipes וכל שאר הסלט. מצאתי קוד קצר באינטרנט שאמור להדגים קצת איך עובדים עם pipes, רק שהוא מציג לי warning שלעולם לא ראיתי
והאמת אני לא מצליח להבין ממה הם נגרמים.
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main(void)
{
int fd[2], nbytes;
pid_t childpid;
char string[] = "Hello, world!\n";
char readbuffer[80];
pipe(fd);
if((childpid = fork()) == -1)
{
perror("fork");
exit(1);
}
if(childpid == 0)
{
/* Child process closes up input side of pipe */
close(fd[0]);
/* Send "string" through the output side of pipe */
write(fd[1], string, (strlen(string)+1));
exit(0);
}
else
{
/* Parent process closes up output side of pipe */
close(fd[1]);
/* Read in a string from the pipe */
nbytes = read(fd[0], readbuffer, sizeof(readbuffer));
printf("Received string: %s", readbuffer);
}
return(0);
}
implicit declaration of function ‘strlen’ [-Wimplicit-function-declaration]
incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
incompatible implicit declaration of built-in function ‘strlen’ [enabled by default]
ניסיתי להוסיף את הספריות stdlib.h, string.h ועוד כמה זה לא נראה כאילו שינה משהו...יש רעיונות?
היי, אני לומד קצת עבודה עם processes ו pipes וכל שאר הסלט. מצאתי קוד קצר באינטרנט שאמור להדגים קצת איך עובדים עם pipes, רק שהוא מציג לי warning שלעולם לא ראיתי
והאמת אני לא מצליח להבין ממה הם נגרמים.
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main(void)
{
int fd[2], nbytes;
pid_t childpid;
char string[] = "Hello, world!\n";
char readbuffer[80];
pipe(fd);
if((childpid = fork()) == -1)
{
perror("fork");
exit(1);
}
if(childpid == 0)
{
/* Child process closes up input side of pipe */
close(fd[0]);
/* Send "string" through the output side of pipe */
write(fd[1], string, (strlen(string)+1));
exit(0);
}
else
{
/* Parent process closes up output side of pipe */
close(fd[1]);
/* Read in a string from the pipe */
nbytes = read(fd[0], readbuffer, sizeof(readbuffer));
printf("Received string: %s", readbuffer);
}
return(0);
}
implicit declaration of function ‘strlen’ [-Wimplicit-function-declaration]
incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
incompatible implicit declaration of built-in function ‘strlen’ [enabled by default]
ניסיתי להוסיף את הספריות stdlib.h, string.h ועוד כמה זה לא נראה כאילו שינה משהו...יש רעיונות?