<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<!-- question: 382348  -->
  <question type="coderunner">
    <name>
      <text>output-compare</text>
    </name>
    <questiontext format="html">
      <text><![CDATA[This question tries to compare output of two programs in C.<br>The two programs will be merged into a C program before being compiled and run.&nbsp;<br>The output of the two programs will be compared line by line.<br>]]></text>
    </questiontext>
    <generalfeedback format="html">
      <text></text>
    </generalfeedback>
    <defaultgrade>4</defaultgrade>
    <penalty>0</penalty>
    <hidden>0</hidden>
    <idnumber></idnumber>
    <coderunnertype>c_via_python</coderunnertype>
    <prototypetype>0</prototypetype>
    <allornothing>1</allornothing>
    <penaltyregime>10, 20, ...</penaltyregime>
    <precheck>0</precheck>
    <hidecheck>0</hidecheck>
    <showsource>1</showsource>
    <answerboxlines>18</answerboxlines>
    <answerboxcolumns>100</answerboxcolumns>
    <answerpreload></answerpreload>
    <globalextra></globalextra>
    <useace></useace>
    <resultcolumns><![CDATA[[["Output", "got"], ["Comment", "comment"], ["Mark", "awarded"]]]]></resultcolumns>
    <template><![CDATA[""" The template for a question type that compiles and runs a student-submitted
    C program.
"""
import subprocess, sys, json

# get strings
answer = """{{ STUDENT_ANSWER | e('py') }}"""
expected = """{{ TEST.testcode | e('py') }}"""
# join answers into a C code
full = "#include<stdio.h>\n int main(){" + answer + expected +"}"

with open("prog.c", "w") as src:
    print(full, file=src)
{% if QUESTION.parameters.cflags is defined %}
cflags = """{{ QUESTION.parameters.cflags | e('py') }}"""
{% else %}
cflags = "-std=c99 -Wall -Werror"
{% endif %}
return_code = subprocess.call("gcc {0} -o prog prog.c".format(cflags).split())
if return_code != 0:
    print("** Compilation failed. Testing aborted **", file=sys.stderr)

# If compile succeeded, run the code. Since this is a per-test template,
# stdin is already set up for the stdin text specified in the test case,
# so we can run the compiled program directly.
if return_code == 0:
    try:
        output = subprocess.check_output(["./prog"], universal_newlines=True)
    except subprocess.CalledProcessError as e:
        output = e.output

end = output.split("\n")
mark = 0
comment = ''
for i in range (4):
    if end[i] == end[i+4]:
        mark += 1
        comment += "Answer {} right\n".format(i+1)
    else:
        comment += "Line {} wrong\n".format(i+1)

print(json.dumps({'got': output, 'comment': comment, 'fraction': mark/4, 'awarded': mark}))]]></template>
    <iscombinatortemplate></iscombinatortemplate>
    <allowmultiplestdins></allowmultiplestdins>
    <answer><![CDATA[printf("x: \n");
printf("add of x: \n");
printf("add of xp: \n");
printf("indirect x: \n");]]></answer>
    <validateonsave>0</validateonsave>
    <testsplitterre></testsplitterre>
    <language></language>
    <acelang></acelang>
    <sandbox></sandbox>
    <grader>TemplateGrader</grader>
    <cputimelimitsecs></cputimelimitsecs>
    <memlimitmb></memlimitmb>
    <sandboxparams></sandboxparams>
    <templateparams></templateparams>
    <hoisttemplateparams>1</hoisttemplateparams>
    <templateparamslang>None</templateparamslang>
    <templateparamsevalpertry>0</templateparamsevalpertry>
    <templateparamsevald>{}</templateparamsevald>
    <twigall>0</twigall>
    <uiplugin></uiplugin>
    <uiparameters></uiparameters>
    <attachments>0</attachments>
    <attachmentsrequired>0</attachmentsrequired>
    <maxfilesize>10240</maxfilesize>
    <filenamesregex></filenamesregex>
    <filenamesexplain></filenamesexplain>
    <displayfeedback>1</displayfeedback>
    <giveupallowed>0</giveupallowed>
    <testcases>
      <testcase testtype="0" useasexample="0" hiderestiffail="0" mark="1.0000000" >
      <testcode>
                <text><![CDATA[printf("x: \n");
printf("add of x: \n");
printf("add of xp: \n");
printf("indirect x: ");
return 0;]]></text>
      </testcode>
      <stdin>
                <text></text>
      </stdin>
      <expected>
                <text></text>
      </expected>
      <extra>
                <text></text>
      </extra>
      <display>
                <text>SHOW</text>
      </display>
    </testcase>
<file name="abc.c" path="/" encoding="base64">I2luY2x1ZGU8c3RkaW8uaD4NCg0KaW50IG1haW4oKQ0Kew0KICAgIGludCB4ID0gNTA7DQogICAgaW50ICp4cCA9ICZ4Ow0KICAgIA0KICAgIHByaW50ZigieDogJWRcbiIsIHgpOw0KICAgIHByaW50ZigiYWRkIG9mIHg6ICVwXG4iLCAmeCk7DQogICAgcHJpbnRmKCJhZGQgb2YgeHA6ICVwXG4iLCAmeHApOw0KICAgIHByaW50ZigiaW5kaXJlY3QgeDogJWRcbiIsICp4cCk7DQogICAgDQogICAgcmV0dXJuIDA7DQp9</file>
    </testcases>
  </question>

</quiz>