C Notes:


// One liner comment
/* Multiline comment */

Compile Notes
gcc -o testProgram testProgram.c
cc -o testProgram testProgram.c
// Compile a program

make testProgram 
// Use make to compile the program

CFLAGS="-Wall" make testProgram 
// Turn on compiler warnings when making the program

CFLAGS="Wall -g" make testProgram
// -g flag for debugging

// When using: #include 
// Compile with option: -ledit

cc -lm -o superProg superProg.c
Link to maths library

ar t /usr/lib/libraryFile
// Show the contents of a library file, to get more info
// about it.

// Location of common library files

// Location of common header files for includes
// Example: stdio.h
// Take a look at the files for more info.

#include "someHeader.h"
The <> search the system locations for the header file
The "" search the current directory for the header file

valgrind ./testProgram
valgrind --track-origins=yes ./testProgram
Valgrind is a program that checks for memory errors

int main()

  printf("Not this again!\n");
  // Simple print statement

  char *later[] = {
    "Katia", "Tazia",
    "Envia", "Tesla"
  // An array of strings

  char *yourname = "Kikay";
  printf("Hello %s!\n", yourname);
  // Create a string array and print it out.

  char myname[5] = {'J', 'a', 'k', 'e', '\0'};
  printf("I am %s\n", myname);
  // One way to build a string with char, below is another.
  // Char uses '' with %c
  // Strings use char[] "" with %s

  // Sample string compare if statement
  char answer[] = "yes";

  if (strcmp(answer,"yes") == 0) {
    printf("c is easy");
    printf("find better way to spend time\n");



C Reference Online

gdb tutorial

Valgrind tutorial (can save hourse of debugging)