C Notes:

default

 
// 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
-lm
Link to maths library

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

/lib
/usr/lib
// Location of common library files

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

#include 
vs
#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







#include 
#include 
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");
  }
  else
  {
    printf("find better way to spend time\n");
  }


}





Links
-----

http://en.cppreference.com/w/c
C Reference Online

http://web.archive.org/web/20140910051410/http://www.dirac.org/linux/gdb/
gdb tutorial

http://www.cprogramming.com/debugging/valgrind.html
Valgrind tutorial (can save hourse of debugging)

default