-3

For example, if I have the C files:

game.c
int main(){
    //code
    }

hello.c
int something(){
    //code
}

How would I get the output to be:

/directory/path/game.c
int main()

/directory/path/hello.c
int something()

I've already written a for loop to iterate through the files ending in .c in a directory, but am unsure on how to output the function names?

So Im trying to execute a shell script which will read the C files and then output its function names.

for file in $(find $1 -type f -name '*.c')
do
    echo $file
    grep -r "what to search for??"

done
ian
  • 33
  • 5

1 Answers1

0

You can use regular expression to pull out the function declarations from the files. You can look here: Regex to pull out C function prototype declarations?

If the line matches the regular expression, you can print it.

Syed Waris
  • 1,056
  • 1
  • 11
  • 16
  • 1
    I think you’ve missed the point of the question. The shell script should list the functions defined in the source files. – Jonathan Leffler Mar 30 '18 at 08:03
  • Actually I thought that since the user has inserted `//code` inside his 2 functions in the question, he is asking for some code inside the function itself. Thank you for pointing – Syed Waris Mar 30 '18 at 08:09