$system$/Questions for exportTest C Prog with argsWrite a program that echoes every line of stdin to stdout, each line prefixed by all args concatenated, excluding arg[0].]]>1.00000000.00000000C_prog_with_args0110, 20, ...00181001
#include
int main(int argc, char** argv) {
bool donePrefix = false;
int c;
while ((c = getchar()) != EOF) {
if (!donePrefix) {
for (int i = 1; i < argc; i++) {
printf("%s", argv[i]);
}
donePrefix = true;
}
putchar(c);
if (c == '\n') {
donePrefix = false;
}
}
}]]>0./prog this that otherLine 1
Line 2
Line 3thisthatotherLine 1
thisthatotherLine 2
thisthatotherLine 3SHOW./progLine 1
Line 2
Line 3Line 1
Line 2
Line 3SHOW./prog a b c d e f g hLine 1
Line 2
Line 3abcdefghLine 1
abcdefghLine 2
abcdefghLine 3SHOWUOC_PROTOTYPE_C_prog_with_argsA C write-a-program question type which is tested by passing arguments to the program (plus stdin if required). The compiled and linked student program is always named prog.
For questions of this type the Test Code in each test is the bash command line to run for testing, e.g.
./prog arg1 arg2
Standard input can be supplied in each test case as well, if needed.
]]>1.00000000.00000000C_prog_with_args2110, 20, ...00181001
0:
# Ignore non-zero positive return codes
if e.output:
print(e.output)
else:
# But negative return codes are signals - abort
if e.output:
print(e.output, file=sys.stderr)
if e.returncode < 0:
print("Task failed with signal", -e.returncode, file=sys.stderr)
print("** Further testing aborted **", file=sys.stderr)]]>
000python3CEqualityGrader