Page 784 - IT2
P. 784
Indication : on suppose que vous disposez d’une fonction fact(n) pour calculer la factoriel
d’un entier n.
PARTIE 2 : PRATIQUE (80 pts)
Dossier1 : LANGAGE DE PROGRAMMATION STRUCTUREE (70 pts)
Exercice1 : (14 pts)
Soit le programme C suivant :
#include <stdio.h>
#include <string.h>
main()
{
FILE* f1;
FILE* f2;
int num;
char nom[20],prenom[20];
f1=fopen("f1.txt","r");
f2=fopen("f2.txt","w");
if(f1!=NULL && f2!=NULL)
{
while(!feof(f1))
{
fscanf(f1,"%d\t%s\t%s\n",&num,nom,prenom);
if(strcmp(prenom,"Mohamed")!=0)
fprintf(f2,"%d\t%s\t%s\n",num,nom,prenom);
}
fclose(f1);
fclose(f2);
}
else
printf("problème d'ouverture de fichier");
}
1) Quel est le rôle de la fonction « strcmp » ? (3 pts)
2) Que signifie while( !feof(f1))? (3 pts)
3) Le fichier « f1.txt » contient le texte suivant :
Filière Epreuve Session
3/7
DI(CDS de 1 à 2) Synthèse V1 Juillet 2016
www.itlearning-settat.com
Email: admission@itlearning-settat.com
Tél.:0661077812

