This commit is contained in:
Emmanuel Srivastava
2024-12-08 23:45:04 +01:00
parent ce726a40b3
commit 642ed7f857
18 changed files with 337 additions and 0 deletions

Binary file not shown.

Binary file not shown.

View 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);
}

View 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);
}

View 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);
}

View File

@@ -0,0 +1 @@
J'ai 18 ans Bonjour

View 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;
}

View 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;
}

View 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;
}

View File

@@ -0,0 +1,2 @@
Emmanuel 18 1000
Toto 47 365

View 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);
}

View 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);
}

View 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);
}

View File

@@ -0,0 +1 @@
Foul tarnished, in search of the Elden ring