Cheatsheet für C
- ANSI-C-Referenz --> http://www.digilife.be/quickreferences/QRC/C%20Reference%20Card%20%28ANS...
- Einführungen in C --> http://www.c-howto.de/tutorial.html
- Schlüsselwörter von C --> http://home.fhtw-berlin.de/~junghans/cref/SYNTAX/keywords.html
- Standard C Library
#include <stdio.h> /* input and output functions */
#include <string.h> /* string related functions */
#include <stdlib.h> /* memory allocation, rand, and other functions */
#include <math.h> /* math functions */
#include <time.h> /* time related functions */ - Funktionen in C
- C-Funktionen --> http://home.fhtw-berlin.de/~junghans/cref/FUNCTIONS/funcref.html
- Variablen in C
häufig: char c (1 Byte), int i (2 Byte), float x (4 Byte), double zahl (8 Byte) // implementierungsabhängig, besser mit sizeof() testen - Formatierungszeichen in C
- Schleifen in C
break;
continue; - Wahr und Falsch in C
0 ... false, Rest ist true - Arrays in C
double jahrestemperatur[12][31]; - Pointer in C
int i; int *adresse; int wert;
i = 5;
addresse = &i; /* Adressoperator */
wert = *adresse; /* Dereferenzierungsoperator */
printf("%d\n",wert); /* 5 = der Wert von i */ - Strings in C
char text[10] = "text"; // oder strcpy()
text[strlen(text)-1] = '\0'; // um das letzte Zeichen kuerzen - Strukturen in C
struct punkt {float x; float y;};
struct punkt p[20]; p[15].x; - Dateien in C
FILE *fp;
fp = fopen("file.txt", "r");
if(fp == NULL) printf("Datei konnte NICHT geoeffnet werden.\n");
fclose(fp); - Warteschleifen in C
Sleep(millisecs); /* Windows; #include <windows.h> */
sleep(millisecs * 1000); /* Linux; #include <unistd.h> */ - Zeitfunktionen in C
time(0); - Zufallszahlen in C
srand(time(0)); r = rand(); - argv in C
#include <stdio.h>
int main(int argc, char *argv[]){
int i;
for(i=0; i<argc; i++) {
printf("%d. Argument: \"%s\"\n",i, argv[i]);
}
return 0;
}
Klassifikation
• C • isa:Cheatsheet