top of page

Some Basic Notes on C

Thanks to Daniel Weller and Sharat Chikkerur who wrote MIT's 6.087 course that is available on MIT OCW, I have been learning the basics of C. I wanted to make some notes on how to do simple tasks in C, mainly for my own reference later:

  • Download MinGW as a C compiler

  • Use Sublime text editor to write programs

  • Use Windows command prompt to compile and run programs

Using command prompt (or any command line interface) is a little tricky, and I've found that most of the commands I learned for Linux computers (which is MIT's preferred OS as you can see in their OCW course) doesn't work in Windows. The only ones that have worked so far are:

cd [insert directory here] :- this takes you to your defined directory

cd .. :- this goes up one directory level

cd \ :- this takes you to the root level directory

To compile a C program using command prompt (assuming that the .c file is saved in the bin folder inside the MinGW folder where the compiler is located) [1]:

gcc -o0 -Wall -std=c99 [filename.c] -o [filename.exe]

To run a C program safely [1]:

gdb [filename.exe]

Then when prompted, type "r". This runs the program. After the program is run, type "q" to exit out of gdb.

gcc is the GNU Compiler Collection which is a group of compilers for various languages, including C. The modifiers (the items beginning with a dash) do various things [1]:

-g :- embed debugging info

-o0 :- disables optimization

-Wall :- enables most compiler warnings

-std=c99 :- tells the compiler to compile to a specific standard, in this case the 1999 standard

-o :- indicates the desired output file name

gdb is a debugger developed by the GNU Project. It is a safe way to run a program on your machine [1].

Sources:

[1] Weller, D and Chikkerur, S, MIT OCW 6.087 Practical Programming in C, https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-087-practical-programming-in-c-january-iap-2010/index.htm.


bottom of page