Home Page

Key ANSI-C
From Writing to Running


Write: Pre-Processor Commands

Command w/ ExampleComment
#include "sdba.h"
#include <stdio.h>
Import info (e.g. data, functions) fr other files
#define MB 256 Replace MB everywhere with 256
#if TEST==1
#elif TEST==2
#endif
Compile only part of code

Write: Data Structures, Flow, Streams

Data TypesFormatFlowStreams
char abc;
long int k;
double x;
char bb[MB];
struct Mi mi;  
  %c || %d  
%ld
%lf
%s
??
while(k<MB){}

if(){} else{ }
stdin
stdout
stderr
char *ptr;   for(k=0;k<MB;k++){ }  

Write: Standard Library Functions (Key)

libraryFunction w/ ExampleComment
<stdio.h> FILE *fi=fopen("in.txt","r");Open file to read
<stdio.h> FILE *fo=fopen("out.txt","w");Open file to write
<stdio.h> fgets(bb,MB,fin);input: string (line of text ended by ␍)
<stdio.h> fscanf(fi,"%ld,%lf",&k,&x);input: 2 numbers (fixed, float)
<stdio.h> fprintf(fo,"k=%ld, x=%lf",k,x); output: anything/where
<stdio.h> fclose(fi);   fclose(fo); close file streams
<string.h> ptr=strtok(bb,",");
 ptr=strtok(NULL,",");
Parse a string: 1st call
Parse a string: following calls
<stdlib.h> j=atod(bb); || j=atod(ptr); Convert string → integer (fixed dec.)
<stdlib.h> x=atof(bb); || x=atof(ptr); Convert string → Real number (float dec.)
<stdlib.h> ptr=calloc(MB,sizeof(char));memory reserve
<stdlib.h> free(ptr);memory release

Compile → Link → Run ⇔ Debug

Compile gcc -c -Wall -g main.c  Gnu
DeBug
(Step)
 gdb m.exe
    b main
    r
    display var
    n
Link  gcc -o m.exe main.o supp.o 
Run  m.exe