I need to find all string definitions in a C project that contains a certain word.
For example given a file called test.c
:
int main(int argc, char** argv)
{
int hello = 0;
string str = "hello world";
printf(str);
return 0;
}
Expected:
print(check_code_for_word_in_str('test.c','hello'))
>>> ./test.c:4: string str = "hello World";
Would be nice if the line number where the string is found is also displayed.
Note how the variable hello = 0
is not printed.
I've checked similar things with ats
parsing python
code. But no idea how to do for c
code.