Your problem is not with pipe. Two header files missing in your codes and for which it is crashing when calling wait() function. Add below two header files in your program and it will fix your problem. Also your declaration of main
function is old c type declaration make it like void main()
.
<sys/types.h>
<sys/wait.h>