in reply to S simple C checking script

Somewhat depending on what you consider to be a C file, that is a highly non-trivial task! I don't think the compiler test would satisfy me because it would generate too many false negatives and maybe even some false positives. I've written plenty of files that I would consider C (or C++) files, but which a compiler would fail to compile, either because of missing header files or because of syntax errors.

In like fashion probing the file for interesting common character sequences is likely to be rather error prone.

What is your friend's use case? Often if you focus just on solving the problem for the use case you can simplify the solution and end up with something that is robust for the task at hand. For example just matching files that have a .c extension may be sufficient and is very easy, fast to implement and very fast executing.

True laziness is hard work

Replies are listed 'Best First'.
Re^2: S simple C checking script
by heatblazer (Scribe) on Mar 28, 2012 at 09:37 UTC

    Well it appears that parsing some gcc output would be nice too. I agree that a simple grep emulation for finding .c and .h files is as easy as this but it`s not the real problem solver since nothing is stopping you to write some perl/js/html in .c or .h files... or just some rubbish ascii text with no particular task. My idea is : if it`s compiled - it`s a C.