3

I would like to know which files do not include a particular header file in C.

For example:

file1.c

#include "stdio.h" #include "my.h" 

...

file2.c

#include "stdio.h" 

....

I would like to find out similar files (like file2.c) which do not contain #include "my.h".

1
  • Note that you should be writing #include <stdio.h> because that's what the C standard uses. Commented Sep 20, 2011 at 6:22

2 Answers 2

3

On Unix systems:

grep -L '#include.*my\.h' *.c 
Sign up to request clarification or add additional context in comments.

1 Comment

This lists files which contain at least one line which doesn't match the regex.
1
shopt -s nullglob for file in *.c do if grep -q "my.h" "$file" ;then continue else echo "found file that don't have my.h" fi done 

Or you could use:

grep -L "my.h" *.c 

if you have nothing else to process except to echo out file names. :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.