cribsheet_total2-2 - C PROGRAM C Comments COMPILATION...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
C PROGRAM: Comments: /**/ Preprocess directives C statements Function headers Type declaratives C COMPILATION: 1. Source 2. Preprocessor 3. Translate to object 4. Executable PREPROCESS DIRECTIVES: #include <systemfile.h> #include "/foo/bar/my.h" #define MAX 30 Macro: #define area(b,h) 1./2.*(b)*(h) Note – there must be parentheses on b, h in fcn., no semi-colon #ifdef SUN_CPU #else #endif DATA TYPES Int – fixed point representation Float – floating point representation FUNCTIONS: fopen ( “filename”, “r”/“w”) fscanf ( *file , “format” , int getchar (void ) – returns next character read from standard input or EOF if end of file; declared as int rather than char because value of EOF may not be in range allowed for char data type. int fgetc (FILE *)– returns next character read from file pointed to by argument or EOF if end of file or error. int getc (FILE *)—same as fgetc except usually implemented as macro. int putchar (int character) ) – write single character argument to standard output (may not actually appear until new line is written due to buffering) Returns character written or EOF in case of error int fputc (int character ,FILE * fileptr) )—writes character which is first argument to file pointed to by fileptr; returns the character written if successful or EOF in case of error. int putc (int character ,FILE *fileptr)—same as fputc except usually implemented as macro #include <ctype.h> int isalnum (int c) int isalpha (int c) int iscntrl (int c) int isdigit (int c); int islower (int c) int ispunct (int c); int isspace (int c) int isupper (int c); int tolower (int c) - given an uppercase letter c , the equivalent lowercase letter is returned; otherwise c is returned int toupper (int c); given a lowercase letter c, the equivalent uppercase letter is returned; otherwise c is returned GCC CODES -pedantic: give an error -lm: link to math library - O0 : no optimization ( O zero) -ansi: use ansi C -o output file CASTING (int) k, or (double) k sizeof() is a function to get if (exp) {statements; } switch (exp) { case const1: commands; break; default: commands; break; } while (exp) { statements; } do { statements; } while (exp); for (initial; test; change) { statements; } Conditional/Ternary Operator exp1 ? exp2 : exp3 - > if (exp1) { return exp2; } else { return exp3; } break – break out of loop continue – jumps to next test expression Post/Pre De/Increment a=3,b=7; b=a++; printf("%d %d\n",a,b); Output: 4 3 b=++a; printf("%d %d",a,b); Output: 4 4 Cannot do with expressions: Example: (a++)++ Difference of data types Signed: one bit is reserved for sign Unsigned: all bits are for values Note: these are only for char and int Short int and long int: these are abbreviated by short and long FLOATING TYPES float < double < long double Characters there is a whitespace that makes it skip 0-50 characters of whitespace FUNCTIONS: Definition – begins with header and can't be inside main Invocation – calling the
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/26/2011 for the course ECE 3331 taught by Professor Staff during the Fall '08 term at University of Houston.

Page1 / 6

cribsheet_total2-2 - C PROGRAM C Comments COMPILATION...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online