Q:

BASH script that generates a header file with function prototypes

I am doing a C project which involves lots of static linking.
To get rid of "implict function declaration" errors I will use a simple solution - a header file with function prototypes.
I wrote this script:
#!/bin/bash
for file_to_parse in `find -type f -name "*.c"`; do
    cproto $file_to_parse > proto.h 2> /dev/null
done

It should create a file called proto.h and store function prototypes there.
Notes:
find -type f -name "*.c" this command returns the pathnames of all c files in the directory of this script.
eg ./folder1/file1.c
cproto <i>file</i> => this creates function prototypes from functions found in file.
eg <code>double myfunction(int a,char b);
Problem:
The code generates an empty file.
What is wrong with this bash script?

A:

There are surely many ways to change it. Here is but one:
 #!/bin/bash
 if [ ! -f proto.h ]; then
       touch proto.h
 fi
 for file_to_parse in `find -type f -name "*.c"`; do
    cproto $file_to_parse >> proto.h 2> /dev/null
 done

The error is in the redirection in the cproto... line: the simple > first wipes the destination file, then writes into it. Instead, >> appends to the destination file without destroying it. The if loop is there just to make sure that at the first pass you will not be appending to a non-existent file: there is nothing wrong with appending to a non-existent file, no error is thrown; it's just that I like to make sure it is a simple, regular file, before writing to it. 

