networking · beginner · ~15 min

Bytes left to send

Track progress through a partial-send loop.

Challenge

send() may transmit only part of the buffer, so a correct sender loops, advancing by each call's return value. Compute how many bytes are still unsent.

Task

Implement int bytes_remaining(int total, int sent) that returns total - sent, but never less than 0.

Input

  • total: total bytes to send.
  • sent: bytes sent so far.

Output

Returns the number of bytes still unsent, floored at 0.

Example

bytes_remaining(100, 30)    ->   70
bytes_remaining(100, 100)   ->   0
bytes_remaining(100, 120)   ->   0

Edge cases

  • If sent exceeds total, return 0 (never a negative count).

Input format

Two integers: total bytes to send and bytes already sent.

Output format

total - sent, never below 0.

Constraints

Floor the result at 0.

Starter code

int bytes_remaining(int total, int sent) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.