update
This commit is contained in:
BIN
DEV.1.1/Allocation_dynamique/1.Singletons
Executable file
BIN
DEV.1.1/Allocation_dynamique/1.Singletons
Executable file
Binary file not shown.
BIN
DEV.1.1/Allocation_dynamique/2.Palindromes
Executable file
BIN
DEV.1.1/Allocation_dynamique/2.Palindromes
Executable file
Binary file not shown.
17
DEV.1.1/Fichiers/ecriture-fichier/fprintf.c
Normal file
17
DEV.1.1/Fichiers/ecriture-fichier/fprintf.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*fprintf(<fichier>, <format>, ...) : écrit du texte formaté*/
|
||||
int main(void){
|
||||
FILE *fic = fopen("text.txt", "w");
|
||||
char mot[]="Bonjour";
|
||||
int age=18;
|
||||
|
||||
if(fic==NULL)
|
||||
{exit(1);}
|
||||
|
||||
fprintf(fic, "J'ai %d ans %s", age, mot);
|
||||
|
||||
fclose(fic);
|
||||
|
||||
}
|
15
DEV.1.1/Fichiers/ecriture-fichier/fputc.c
Normal file
15
DEV.1.1/Fichiers/ecriture-fichier/fputc.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*fputc(<caractère>, <fichier>) : écrit un caractère*/
|
||||
int main(void){
|
||||
FILE *fic = fopen("text.txt", "w");
|
||||
|
||||
if(fic==NULL)
|
||||
{exit(1);}
|
||||
fputc('J',fic);
|
||||
fputc('O',fic);
|
||||
|
||||
fclose(fic);
|
||||
|
||||
}
|
16
DEV.1.1/Fichiers/ecriture-fichier/fputs.c
Normal file
16
DEV.1.1/Fichiers/ecriture-fichier/fputs.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*fputs(<chaîne de caractère>, <fichier>) : écrit une chaîne de caractère*/
|
||||
int main(void){
|
||||
FILE *fic = fopen("text.txt", "w");
|
||||
char mot[]="Bonjour";
|
||||
|
||||
if(fic==NULL)
|
||||
{exit(1);}
|
||||
|
||||
fputs(mot,fic);
|
||||
|
||||
fclose(fic);
|
||||
|
||||
}
|
1
DEV.1.1/Fichiers/ecriture-fichier/text.txt
Normal file
1
DEV.1.1/Fichiers/ecriture-fichier/text.txt
Normal file
@@ -0,0 +1 @@
|
||||
J'ai 18 ans Bonjour
|
21
DEV.1.1/Fichiers/lecture-ficher/openfile-fgetc.c
Normal file
21
DEV.1.1/Fichiers/lecture-ficher/openfile-fgetc.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void){
|
||||
FILE *fic = fopen("text.txt", "r");
|
||||
int lettre = 0;
|
||||
|
||||
if(fic == NULL){
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while((lettre = fgetc(fic)) != EOF){
|
||||
printf("%c", lettre);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
fclose(fic);
|
||||
|
||||
return 0;
|
||||
}
|
21
DEV.1.1/Fichiers/lecture-ficher/openfile-fgets.c
Normal file
21
DEV.1.1/Fichiers/lecture-ficher/openfile-fgets.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void){
|
||||
FILE *fic = fopen("text.txt", "r");
|
||||
char lettre[256];
|
||||
|
||||
if(fic == NULL){
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while(fgets(lettre, 255, fic) != NULL){
|
||||
printf("%s", lettre);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
fclose(fic);
|
||||
|
||||
return 0;
|
||||
}
|
23
DEV.1.1/Fichiers/lecture-ficher/openfile-fscanf.c
Normal file
23
DEV.1.1/Fichiers/lecture-ficher/openfile-fscanf.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void){
|
||||
FILE *fic = fopen("text.txt", "r");
|
||||
char texte[256];
|
||||
int age = 0;
|
||||
int Nombre = 0;
|
||||
|
||||
if(fic == NULL){
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fscanf(fic, "%s %d %d", texte, &age, &Nombre);
|
||||
printf("Nom : %s\n", texte);
|
||||
printf("Age : %d\n", age);
|
||||
|
||||
printf("\n");
|
||||
|
||||
fclose(fic);
|
||||
|
||||
return 0;
|
||||
}
|
2
DEV.1.1/Fichiers/lecture-ficher/text.txt
Normal file
2
DEV.1.1/Fichiers/lecture-ficher/text.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
Emmanuel 18 1000
|
||||
Toto 47 365
|
24
DEV.1.1/Fichiers/positionnement-fichier/fseek.c
Normal file
24
DEV.1.1/Fichiers/positionnement-fichier/fseek.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*fseek(<fichier>, <déplacement>, <origine>) : déplace curseur
|
||||
-> <origine> : SEEK_SET (début du fichier)
|
||||
SEEK_CUR (position courante)
|
||||
SEEK_END (fin du fichier)
|
||||
*/
|
||||
int main(void){
|
||||
FILE *fic = fopen("text.txt", "r");
|
||||
|
||||
if(fic==NULL)
|
||||
{exit(1);}
|
||||
|
||||
printf("Position : %d\n", ftell(fic));
|
||||
|
||||
fseek(fic,5,SEEK_SET);
|
||||
|
||||
printf("Position : %d\n", ftell(fic));
|
||||
|
||||
|
||||
fclose(fic);
|
||||
|
||||
}
|
17
DEV.1.1/Fichiers/positionnement-fichier/ftell.c
Normal file
17
DEV.1.1/Fichiers/positionnement-fichier/ftell.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*ftell(<fichier>) : retourne la position du curseur dans le fichier
|
||||
*/
|
||||
int main(void){
|
||||
FILE *fic = fopen("text.txt", "r");
|
||||
int position_cur = -1;
|
||||
|
||||
if(fic==NULL)
|
||||
{exit(1);}
|
||||
|
||||
printf("Position %d\n", ftell(fic));
|
||||
|
||||
fclose(fic);
|
||||
|
||||
}
|
24
DEV.1.1/Fichiers/positionnement-fichier/rewind.c
Normal file
24
DEV.1.1/Fichiers/positionnement-fichier/rewind.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*rewind(<fichier>) : réinitialise la position du curseur
|
||||
*/
|
||||
int main(void){
|
||||
FILE *fic = fopen("text.txt", "r");
|
||||
int position_cur = -1;
|
||||
if(fic==NULL)
|
||||
{exit(1);}
|
||||
|
||||
printf("Position : %d\n", ftell(fic));
|
||||
|
||||
fseek(fic,5,SEEK_SET);
|
||||
|
||||
printf("Position : %d\n", ftell(fic));
|
||||
|
||||
rewind(fic);
|
||||
|
||||
printf("Position : %d\n", ftell(fic));
|
||||
|
||||
fclose(fic);
|
||||
|
||||
}
|
1
DEV.1.1/Fichiers/positionnement-fichier/text.txt
Normal file
1
DEV.1.1/Fichiers/positionnement-fichier/text.txt
Normal file
@@ -0,0 +1 @@
|
||||
Foul tarnished, in search of the Elden ring
|
Reference in New Issue
Block a user