Checking Function Exist in Program.

Checking Function Exist in Program.

by Manoj Kumar Singh -
Number of replies: 3

i desperately need help of a  problem. i would like to know that how test student made program by function.

suppose i made a program in c language like 

void add();

void main()

{

add();

}

void add()

{

printf("hello");

}

i want to create evaluate.sh file who check function available in function. if available then grade 100% else 0.

Average of ratings: -
In reply to Manoj Kumar Singh

Re: Checking Function Exist in Program.

by Juan Carlos Rodríguez-del-Pino -
Picture of Particularly helpful Moodlers Picture of Plugin developers
Dear Manoj Kumar Singh,
To be sure the students create a function you must use it. To get it you may do the following:
Request the students to write the add function, but not the main function, in the add.c file (use requested files to ensure the file name).
write a program "useAdd.c" in the "execution files" with the code:
#include "add.c"
int main(){
 add();
 return 0; }
Best regards,
Juan Carlos.
In reply to Juan Carlos Rodríguez-del-Pino

Re: Checking Function Exist in Program.

by Manoj Kumar Singh -
Its great privilege to me that you reply me. Its definitely great answer you reply me. but my question is different, i want o evaluate the answer automatic.
So i would like to share with you my code which check function exist in program or not, i also know that its not complete code. but its work.

#! /bin/bash
3 cat > vpl_execution < 4 #! /bin/bash
5 prog=fun
6
7 # remove the comments from the source file
8 cat \${prog}.c | sed 's:;.*$::g' > _\${prog}.c
9
10 grep "()$" \${prog}.c > cut_fun_line
11 cut -d' ' -f2 cut_fun_lin > cut_fun_line1
12
13 for i in 'cat \${prog}.c' ; do
14 if [ $i -eq $cut_fun_lin1 ] ; then
15 echo "Comment :=>>You are using function \$i in your code"
16 echo "Grade :=>> 100"
17
18 fi
19 done
20 EOF
21 chmod +x vpl_execution

Kindly help me to improve this program.
In reply to Manoj Kumar Singh

Re: Checking Function Exist in Program.

by Manoj Kumar Singh -
Kindly help me to run following program in moodle.

# first i made file in shell prompt 
cat  > fun
def add()
^d

then i write shell script
fun_check.sh

cat fun |  grep "def" fun  > file1

#grep "def" fun > file1
cat file1
cat file1 | head -n1 | cut -d " " -f1 >file2
cat file2

# content=$(cat file2)
#--- remove multiple spaces ---
     cat file2 | sed 's/  */ /g' > dummy
content=$(cat dummy)
echo "content" $content
s="def"

if [ "$s" == "$content" ]
then
   echo "with function"
else
echo "without function"
fi

This program perfectly run in shell prompt
but when i try to execute this program in moodle it is not working.

Actually i want that my shell script program  check function available in python program or not.
and i want that student get  grade automatic  if student  write program by  function.

When i write above program in evaluate.sh file then it shows command not found error cat, grep so on.

kindly help me to execute above program in moodle.