![]() | Key ANSI-C
Keys | Simple Program | Simple CMD line
|
Command w/ Example | Purpose |
---|---|
#include <stdio.h> #include "jinlib.h" | Import info (e.g. data, functions) fr other files e.g. function prototypes |
#define MB 8 | Replace MB with 8 everywhere |
#if MB==1 #elif MB==8 #endif | Compile only part of code |
Data Types | io Format | Purpose |
---|---|---|
char abc; | %c || %d | one byte |
long int k; | %ld | integer |
double x; | %lf | float 0.6e5 |
char *ptr; | %p | address |
char bb[MB]; | %s || - | array & strings |
struct Mi mi; | - | record |
Flow | Streams |
---|---|
while(k<MB){k++;} | stdin |
if(k<=MB){x=0.0;} else{x=1.0;} | stdout |
for(k=0;k<MB;k++){x=x+k;} | stderr |
library | Function w/ Example | Comment |
---|---|---|
<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> | fscanf(fi,"%ld,%lf",&k,&x); | input: 2 numbers |
<stdio.h> | fprintf(fo,"k=%ld, x=%lf",k,x); | output: anything/where |
<stdio.h> | fclose(fi); fclose(fo); | close file streams |
<stdio.h> | fgets(bb,MB,fin); | input: string (end: ␍) |
<string.h> | ptr=strtok(bb,","); ptr=strtok(NULL,","); | Parse string: 1st call Parse string: next calls |
<stdlib.h> | j=atod(bb); | string(text) → long |
<stdlib.h> | x=atof(bb); | string(text) → double |
<stdlib.h> | ptr=calloc(MB,sizeof(char)); | memory reserve |
<stdlib.h> | free(ptr); | memory release |
gcc -c -Wall -g main.c | Compile C-Code |
gcc -o m.exe main.o jinlib.o | Link Binaries |
m.exe | Run Program |