There are few problems with your program:
- You are not checking returned values of read, write and execle in prog2.c
- You are sending "7+5+11=?\n" string which is 10 characters long but only expecting 4 characters ( 3+4+5 is not even four characters ).
- Also "off" you are sending is 3 characters long but without including null termination.
- When you read from an
fd
you will in both cases not get null terminated string and then you are trying toprintf
it. It's a quick way to undefined behaviour. Put an '\0' after the end of buffer you read from any file descriptor! - Especially what
read
returns is very important as it tells you how many characters were read. You should never ignore returned value ofread
(in some cases it's the same withwrite
function).
Next time also provide some output of your program as it will be easier to give some help.