linux-sysprog · intermediate · ~15 min

Echo argv with indices

Understand argc/argv layout (without depending on the runtime to inject it).

Challenge

Implement int echo_args(int argc, char **argv, char *out, size_t out_sz) that writes each arg into out in the form i: <arg>\n (i starts at 0). Return 0 on success. The grader calls your function with a fixed argv to simulate command-line invocation — you do not run argc/argv from main.

Starter code

#include <stdio.h>
#include <string.h>
#include <stddef.h>

int echo_args(int argc, char **argv, char *out, size_t out_sz) {
    /* TODO */
    return -1;
}

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