An important distinction is what you mean by "checking" these programs. I assume you don't mean actually compiling/running them during runtime (which is what reflection means to me), because you can't check their program structure from a compiled program.
That means you're going to be text processing the source files, and while this is much easier in pretty much every scripting language, it's not that bad in C:
Figure out how to get a list of all the files to be processed. Either put all the file names in an index file, and iterate over that file, OR get a list of files by using readdir
or preferably a library (Boost) to do it for you.
For each file, open it and read each line (Google, it's trivial)
For each line, check it against your rules, and collect the necessary results.
Store result in an array, or write it to a file, etc.
Edit-If you want to check to see if your students' programs run (aka, compile/run them during runtime), you'd probably have to execve
off some gcc calls (if you want to compile), and then again to run the program. However, execve
is only going to tell you if the command failed. Getting output from other programs would mean opening pipes with popen
. If you find yourself ready to do this, turn back, you've gone too far.