Skip to content
Physics and Astronomy
Home Our Teaching Resources C programming #define example
Back to top

Another #define example

Our previous example of using fopen() had an issue in that the file name "highscore.txt" appeared twice. If we ever wanted to change it we would have had to change it twice and the danger is that we would miss one out.

Here is one solution using #define which demonstrates that it can be used for text strings as well as mathematical constants. The changes are shown highlighted.

 
Log in
                                                                                                                                                                                                                                                                       

Validate   Link-check © Copyright & disclaimer Privacy & cookies Share
Back to top