[S3] Reading from the wire

Back in 1977, you want to read your e-mail with your freshly bought Apple II. You are connected to the ARPANET through a modem, but unfortunately the modem's manufacturer has only given a single function modem_read, to read the data received by the modem, with the following prototype :

void modem_read(void *buffer, int *buf_len);

This function fills the supplied buffer with the data received from the modem (an array of char), and writes the number of bytes written to the value pointed by buf_len. It can write up to maximum 256 bytes in a single call. This function is guaranteed to return.


You want to know if the information that you received from the modem you received contains a byte whose numerical value is 42. Write the body of the function has_42, this function has to use malloc to create the buffer before calling modem_read:

 * @return: 1 if the modem received a byte containing 42
 *         else 0, -1 if an error has happened.
int has_42() {


Author(s) Mathieu Xhonneux & Maxime Mawait
Deadline No deadline
Submission limit 12 submissions
every 1 hour(s)
Category Tags S3, Pointer


Sign in