Notices
 

Shell script to automatically evaluate the c program output

For page specific messages
For page author info

We have organised one programming contest in our office. Where, we have given three (3) C proramme to each contestants. They need to submit their written with my script (Which is below). This script takes two command lines input, first is C file and second one is problem number (1,2 and 3). This script compile their code, generate ouput file and check it on some test cases. If users get 'Y' for all test cases, their programme is correct. Otherwise they get 'X'.

 

 

#!/bin/bash
if [ $# -gt 2 ]
then
     echo "Too many Parameters! Please give filename only"
else
     user=`whoami`
     gcc $1 -o sample.out
     a=1
    echo "$1" >> "$user"
    b=`ls /home/aashu/online_exam/ |grep input"$2" | wc -l`
    while [ $a -le $b ]
    do
         ./sample.out < /home/aashu/online_exam/"input$2$a.txt" >"output$2$a"
         diff "output$2$a" /home/aashu/online_exam/"sample$2$a" >/dev/null
        if [ $? -eq 0 ]
        then
            echo "Y"
            echo "Y" >> "$user"
        else
            echo "X"
            echo "X" >> "$user"
         fi
        a=`expr $a + 1`
       sleep 1
    done
 
   echo "--------------" >> "$user"

   if [ -d "/home/aashu/online_exam/submission/$user" ]
   then
      echo "Directory /path/to/dir exists."> /dev/null
   else
     echo "Error: Directory /path/to/dir does not exists."> /dev/null
     mkdir /home/aashu/online_exam/submission/"$user" >/dev/null
   fi
c=`ls /home/aashu/online_exam/submission/"$user"/ | grep $1 |wc -l`
cp $1 /home/aashu/online_exam/submission/"$user"/$c$1
cp "$user" /home/aashu/online_exam/submission/"$user"/"$user"

fi

 

 

Happy Coding CoolLaughing

Exclude node summary : 

n
 
X