Voici un petit mémento des principales syntaxes à connaitre pour programmer en C.
Vous y trouverez les informations concernant les types de données, les entrées et sorties standard,...
gcc -Wall -ansi -c prog.c | gcc -o prog prog.o
ou
gcc -Wall -ansi -o prog prog.c
[long/short] [signed/unsigned] int, float, double, char
auto, static, extern, register
type_de_base nom [nb_elements_optionnel] ;
type nom_tab [dim1][dim2]...[dimn] ;
déclaration: type * var ;
utilisation : Opérateur &, Opérateur *, pointeur NULL
#include <stdlib.h>
void * malloc(size_t size);
void * free(void *p);
void * realloc(void *p, size_t size);
struct <identificateur> {
<type><liste_identificateurs>;
...
<type><liste_identificateurs>;
};
typedef type nouveau_type
#define TAILLE 5
#define MAX(a,b) ((a)>(b))?(a):(b))
int scanf(const char *format, ...);
char *gets(char *s);
int getchar(void);
int printf(const char *format, /* args*/ ...);
int puts(char *ch);
int putchar(int c);
#include <stdio.h>
Format :
FILE*
FILE * fopen(char *nom, char *mode);
mode : "r", "w", "a", "r+", "w+","a+". binaire : ajouter b au mode ("r+b")
fclose(FILE *f);
int feof(FILE *f);
fscanf(FILE *f, const char *format, liste_adresses);
fprintf(FILE *f, const char *format, liste_expressions);
int fgetc(FILE * f);
int fputc(int c, FILE * f);
char *fgets(char *ch, int lgmax, FILE *f);
int fputs(char *ch, FILE *f);
size_t fwrite(const void *ptr, size_t t, size_t nobj, FILE *f);
size_t fread(void *ptr, size_t t, size_t nobj, FILE *f);
int fseek(FILE *f, long offset, int mode);
Mode : 0 par rapport au début du fichier, 1 par rapport à la position courante, 2 par rapport à la fin
long ftell(FILE *f);
int rewind(FILE *f);
int strlen(char * chaine)
char *strcpy(char *destination,char *source)
char *strncpy(char *destination,char *source,int longmax)
char *strcat(char *destination,char *source)
char *strncat(char *destination,char *source,int longmax)
int strcmp(char *str1,char*str2)
long atol(const char *str);
int atoi(const char *str);
int sprintf(char *s, const char *format, /* args*/ ...);
if (expression) instruction
if (expression) instruction1 else instruction2
switch(selecteur)
{
case cas1: instruction1; [break;]
case cas2: instruction2; [break;]
...
case casN: instructionN; [break]
[default: instruction_par_défaut;]
}
while (exp) inst
do inst while (exp);
for (exp1;exp2;exp3) inst
boucles while, do-while et for : break; continue;
int main(int argc,char *argv[ ] )
! + + -- - * / % + - < <= > >= = = != && || = + = -= * = /= %=
\0 fin de chaîne,
\n fin de ligne,
EOF fin de fichier,
\t tabulation,
\\,
\'
/* commentaire */