SlideShare uma empresa Scribd logo
1 de 37
INFORMATIQUE III  DEVOIR SURVEIEE  2 Notes 18  -  20   p.  ( excellent  6);  15  –  17   p . ( tr è s bien  5); 12 – 14 p. (bien 4); 10 – 11 p. (passable 3)
[object Object],[object Object],#include <stdio.h> #include <string.h> #define N 3 typedef struct el { int  inf; char name[15]; }unit; unit f(unit a); int main(){ unit lst[N], *lstp[N]; char p[]=&quot;Paris Sofia&quot;, x,y; for(x=0; x<N; x++){   lst[x].inf=x+1;   strcpy(lst[x].name,p+x);   printf(&quot;1: %s&quot;,lst[x].name+2);   lstp[x]=lst+x; }
[object Object],[object Object],lstp[0]=lstp[2]; for(x=0; x<N; x++){ printf(&quot;2:%d %s&quot;,lstp[x]->inf, lstp[x]->name); } *lstp[1]=f(*lstp[0]);   printf(&quot;4:%d %s&quot;,lstp[1]->inf,lstp[1]->name);   return 0; } unit f(unit a) {  unit b; a.inf*=2; b.inf=(2*a.inf)+1; strcpy(b.name,a.name+4); printf(&quot;3:%d %s&quot;,a.inf,a.name); return b; }
[object Object],unit *lstp[3] unit  lst[3] inf name 1  Paris Sofia 2  aris Sofia 3  ris Sofia
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],#include <stdio.h> int gcd(int, int); int main() { int a=33, b=15; if (a < 1 || b < 1) {  printf(&quot;Erreur! &quot;);   return 1; } printf(&quot;%d&quot;,gcd(a, b)); return 0; } int gcd(int a, int b) {if (a == b) return a; if (a > b) return gcd(a-b, b);   return gcd(a, b-a); }
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],Maria Angelova Ani Koleva Ivan Petrov Asen Milanov
#include<stdio.h> #include<stdlib.h> #include <string.h> #define  NUM 2 void output(char **p,int k); void sort(char **p,int k); char ** insert(char **ptext,int *n_l); int main(void) {  int n_l; char **ptext; ptext=insert(ptext,&n_l); printf(&quot;%d chaines (noms) ont lus&quot;,n_l); printf(&quot;Liste originale des noms:&quot;); output(ptext,n_l); sort(ptext,n_l); printf(&quot;Liste des nom tries:&quot;); output(ptext,n_l); free(ptext);  return(0);  }
char ** insert(char **ptext,int *n_l) { char *p; FILE *fp; int  n_el=NUM ; *n_l=0; char buf[SIZE]; if((fp=fopen(&quot;test.txt&quot;, &quot;r&quot;)) == NULL) {   printf(&quot;Fichier n'est pas ouvert.&quot;);   exit(1); } if((ptext=(char **) malloc ( n_el *sizeof(char *)))==NULL){   printf(&quot;Erreur!&quot;);   exit(1); }
do{ if( fgets(buf,sizeof(buf),fp)== NULL){ printf(&quot;Erreur lecture!&quot;); exit(1); } if((p=(char*)malloc( sizeof(char)*(strlen(buf)+1)))== NULL){ printf(&quot;Erreur!&quot;);   exit(1); } strcpy(p,buf); if(*n_l==n_el) {  n_el+=NUM ; if (ptext=(char**) realloc (ptext, n_el *sizeof(char*)))==NULL){ printf(&quot;Erreur!&quot;);   exit(1); } } ptext[(*n_l)++]=p; } while(!feof(fp)); strcat(*(ptext+*n_l-1),&quot;&quot;); return ptext; }
void output(char **p,int k) { int j; for(j=0;j<k;j++)   printf(&quot;%s&quot;,*(p+j)); } void sort(char **p,int k) { int j,flag; char st[80]; do{  flag=0;   for(j=0;j<k-1;j++)   if(strcmp(*(p+j),*(p+j+1))>0){   flag=1;   strcpy(st,*(p+j));   strcpy(*(p+j),*(p+j+1));   strcpy(*(p+j+1),st);   } }  while(flag); }
 
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <memory.h> #define NBR 5 typedef struct { char name[20]; float averageMark; }STUDENT; void myMenu(); STUDENT * addStudentFromKey(short *); void inputStudent(STUDENT*); void printArray(STUDENT *,short ); FILE *writeStructFile(STUDENT *,short); void sortArray(STUDENT *,short); int sortName(const void *,const void *); int sortAverageMark(const void *,const void *); void SearchFile(FILE *);
int main() { myMenu(); return 0; } ///////////////////////////////////////////////// void myMenu() {  FILE *fp; short a,i; STUDENT *array; do { printf(&quot;1.Creer tableau dynamique des structures - entrees par clavier  2.Afficher le tableau  3.Ecrire le tableau dans un fichier binaire  4.Trier le tableau dynamique des structures  5.Chercher dans le fichier les etudiants avec notes >=5.50&ecrire  6.Fin  Votre choix :&quot;);   scanf(&quot;%d&quot;,&a);
switch(a) { case 1:array=addStudentFromKey(&i);break; case 2:printArray(array,i);break; case 3:fp=writeStructFile(array,i);break; case 4:sortArray(array,i); break; case 5:SearchFile(fp); } }while(a!=6); free(array); }
STUDENT* addStudentFromKey(short *i) {  STUDENT *array,a; char word[4]; int n=NBR; *i=0; array=(STUDENT*)malloc(n*sizeof(STUDENT)); if(array == NULL) exit(1); while(printf(&quot;La structure suivante dans le tableau? - (oui/no)&quot;),    fflush(stdin),strcmp(gets(word),&quot;oui&quot;)==0)   {  if(*i == n)   {  n=n*2;   array=(STUDENT*)realloc(array,n*sizeof(STUDENT));   if(array == NULL) exit(1);   }   printf(&quot;ETUDIANT  NOMBRE %d: &quot;,*i+1);   inputStudent(&a);   memcpy(&array[*i],&a,sizeof(STUDENT));   (*i)++; } return array; }
void inputStudent(STUDENT *a) { fflush(stdin); printf(&quot;Entrer le nom:&quot;); gets(a->name); printf(&quot;Entrer la note moyenne:&quot;); scanf(&quot;%f&quot;,&a->averageMark); } ////////////////////////////////////////////////////////////////////////////////////////// void printArray(STUDENT *array,short n) { int i; printf(&quot;Les elements du tableau dynamique  ETUDIANT  NOMBRE  ETUDIANT NOM    ETUDIANT NOTE MOYENNE&quot;); for(i=0;i<n;i++) printf(&quot;%-18d %-28s %-10.2f&quot;,i+1,array[i].name,array[i].averageMark); }
FILE* writeStructFile(STUDENT *array,short n) { FILE *fp; char fname[15]; short i; puts(&quot;Entrer le nom du fichier pour ecrire&quot;); fflush(stdin); gets(fname); fp=fopen(fname,&quot;w+b&quot;); if(fp==NULL) { printf( &quot;Problem d'ouverture&quot; ); exit(1); } for(i=0;i<n;i++) fwrite(&array[i],sizeof(STUDENT),1,fp); return(fp); }
void sortArray(STUDENT *array,short n) {  short k; printf(&quot;Choix du tri :0 - par nom;1 - par note moyenne&quot;); fflush(stdin); scanf(&quot;%d&quot;,&k); qsort((void*)array,n,sizeof(STUDENT),k?sortAverageMark:sortName); } ////////////////////////////////////////////////////////////////////////////// int sortName(const void *pa,const void *pb) { char x; STUDENT*a=(STUDENT*)pa; STUDENT*b=(STUDENT*)pb; x=strcmp(a->name,b->name); if(x>0) return 1; else if(x<0) return -1; else return 0; }
int sortAverageMark(const void *pa,const void *pb) { STUDENT*a=(STUDENT*)pa; STUDENT*b=(STUDENT*)pb; if(a->averageMark > b->averageMark) return 1; else if(a->averageMark < b->averageMark) return -1; else return 0; }
void SearchFile(FILE *fp) {  FILE *fp_new; char fname_new[15]; STUDENT temp; rewind(fp); puts(&quot;Entrer le nom du fichier pour ecrire&quot;); fflush(stdin); gets(fname_new); fp_new=fopen(fname_new,&quot;w+b&quot;); if(fp_new==NULL) { printf( &quot;Problem problem d'ouverture&quot; ); exit(1); } while(fread(&temp,sizeof(STUDENT),1,fp)==1)   if(temp.averageMark >= 5.50)   fwrite(&temp,sizeof(STUDENT),1,fp_new); rewind(fp_new); while(fread(&temp,sizeof(STUDENT),1,fp_new)==1)   printf(&quot;%-28s %-10.2f&quot;,temp.name,temp.averageMark); fclose(fp); fclose(fp_new); }
 
 
 
 
 
 
[object Object],[object Object]
ppch[0] word0 ppch[1] ppch[2] word1 word2 ppch[i] ppch[n] wordn char **ppch
#include <stdio.h> #include <string.h> #include <stdlib.h> #define NUM 2 void prt(char **ppch,int n){ int i; for(i=0;i<n;i++){ printf(&quot;%s&quot;,ppch[i]); } } int exist(char **ppch, int n, char *w){ int i; for(i=0; i<n;i++){ if(!strcmp(ppch[i],w)) return 1; } return 0; }
char ** insert(char **ppch, int *n_w,int *n_el, char *w){ char *p; if ((p = (char *)malloc(sizeof(char)*(strlen(w)+1)))== NULL){ return NULL; } strcpy(p, w); if(*n_w == *n_el){ *n_el+=NUM; if ( (ppch = (char **)realloc( ppch,*n_el*sizeof(char*)))==NULL)  { return NULL; } } ppch[(*n_w)++]= p; return ppch; }
void sort(char **ppch, int n_w){ int i,ok; char *help; do {  ok=1; for(i=0;i<n_w-1;i++){ if(strcmp(ppch[i],ppch[i+1])>0){ help=ppch[i]; ppch[i]=ppch[i+1]; ppch[i+1]=help; ok=0; } } }while (!ok); } void free_m(char **ppch,int n_words){ int i; for(i=0;i<n_words;i++){ free(ppch[i]); } free(ppch); }
int main(){ int n_words=0,  n_el=NUM ; char buf[251], **ppch; FILE *f; if((f=fopen(&quot;b.txt&quot;,&quot;rt&quot;))==NULL){ printf (&quot;The file cannot be read&quot;); return 2; } if ( (ppch = (char **)malloc( n_el*sizeof(char*)))== NULL){ printf(&quot;No memory&quot;); return 3; } while(!feof(f)) { if( fscanf(f,&quot;%250s&quot;,buf) == EOF){ break; } if(!exist(ppch,n_words,buf)){ if((ppch=insert(ppch, &n_words,&n_el,buf))==NULL){ printf(&quot;No memory&quot;); return 3; } } } sort(ppch, n_words); prt(ppch, n_words); free_m(ppch,n_words); return 0; } alfa alfa  tita gama  beta alfa beta gama tita

Mais conteúdo relacionado

Mais procurados

Cours structures des données (langage c)
Cours structures des données (langage c)Cours structures des données (langage c)
Cours structures des données (langage c)rezgui mohamed
 
Scala : programmation fonctionnelle
Scala : programmation fonctionnelleScala : programmation fonctionnelle
Scala : programmation fonctionnelleMICHRAFY MUSTAFA
 
Seance 3- Programmation en langage C
Seance 3- Programmation en langage C Seance 3- Programmation en langage C
Seance 3- Programmation en langage C Fahad Golra
 
Seance 4- Programmation en langage C
Seance 4- Programmation en langage CSeance 4- Programmation en langage C
Seance 4- Programmation en langage CFahad Golra
 
Les nouveautés de C++11 : Ecrire du C++ Moderne
Les nouveautés de C++11 : Ecrire du C++ ModerneLes nouveautés de C++11 : Ecrire du C++ Moderne
Les nouveautés de C++11 : Ecrire du C++ ModerneMicrosoft
 
Résumé Algorithme et Programmation
Résumé Algorithme et ProgrammationRésumé Algorithme et Programmation
Résumé Algorithme et Programmationborhen boukthir
 
Développer en natif avec C++11
Développer en natif avec C++11Développer en natif avec C++11
Développer en natif avec C++11Microsoft
 
Exercices pascal tous les chapitres
Exercices pascal tous les chapitresExercices pascal tous les chapitres
Exercices pascal tous les chapitresborhen boukthir
 
Chapitre4: Pointeurs et références
Chapitre4: Pointeurs et références Chapitre4: Pointeurs et références
Chapitre4: Pointeurs et références Aziz Darouichi
 
Chapitre2fonctionscppv2019
Chapitre2fonctionscppv2019Chapitre2fonctionscppv2019
Chapitre2fonctionscppv2019Aziz Darouichi
 
Implémentation optimale de filtres linéaires en arithmétique virgule fixe
Implémentation optimale de filtres linéaires en arithmétique virgule fixeImplémentation optimale de filtres linéaires en arithmétique virgule fixe
Implémentation optimale de filtres linéaires en arithmétique virgule fixeBenoit Lopez
 
Initiation au code : Ateliers en C# (applications desktop et mobile native)
Initiation au code : Ateliers en C# (applications desktop et mobile native)Initiation au code : Ateliers en C# (applications desktop et mobile native)
Initiation au code : Ateliers en C# (applications desktop et mobile native)Stéphanie Hertrich
 
Corrige exercices pascal_fenni_2018
Corrige exercices pascal_fenni_2018Corrige exercices pascal_fenni_2018
Corrige exercices pascal_fenni_2018salah fenni
 
09 big data mapreduce
09 big data mapreduce09 big data mapreduce
09 big data mapreducePatrick Bury
 

Mais procurados (20)

Cours structures des données (langage c)
Cours structures des données (langage c)Cours structures des données (langage c)
Cours structures des données (langage c)
 
Scala : programmation fonctionnelle
Scala : programmation fonctionnelleScala : programmation fonctionnelle
Scala : programmation fonctionnelle
 
Seance 3- Programmation en langage C
Seance 3- Programmation en langage C Seance 3- Programmation en langage C
Seance 3- Programmation en langage C
 
Seance 4- Programmation en langage C
Seance 4- Programmation en langage CSeance 4- Programmation en langage C
Seance 4- Programmation en langage C
 
Les nouveautés de C++11 : Ecrire du C++ Moderne
Les nouveautés de C++11 : Ecrire du C++ ModerneLes nouveautés de C++11 : Ecrire du C++ Moderne
Les nouveautés de C++11 : Ecrire du C++ Moderne
 
Résumé Algorithme et Programmation
Résumé Algorithme et ProgrammationRésumé Algorithme et Programmation
Résumé Algorithme et Programmation
 
Le langage C
Le langage CLe langage C
Le langage C
 
C4 fonctions
C4 fonctionsC4 fonctions
C4 fonctions
 
Chap2fonctionscpp
Chap2fonctionscppChap2fonctionscpp
Chap2fonctionscpp
 
Développer en natif avec C++11
Développer en natif avec C++11Développer en natif avec C++11
Développer en natif avec C++11
 
Polymorphisme, interface et classe abstraite
Polymorphisme, interface et classe abstraitePolymorphisme, interface et classe abstraite
Polymorphisme, interface et classe abstraite
 
Exercices pascal tous les chapitres
Exercices pascal tous les chapitresExercices pascal tous les chapitres
Exercices pascal tous les chapitres
 
Chapitre4: Pointeurs et références
Chapitre4: Pointeurs et références Chapitre4: Pointeurs et références
Chapitre4: Pointeurs et références
 
Chapitre2fonctionscppv2019
Chapitre2fonctionscppv2019Chapitre2fonctionscppv2019
Chapitre2fonctionscppv2019
 
Type abstrait de données
Type abstrait de donnéesType abstrait de données
Type abstrait de données
 
Chapitre2 prog dsplf3
Chapitre2 prog dsplf3Chapitre2 prog dsplf3
Chapitre2 prog dsplf3
 
Implémentation optimale de filtres linéaires en arithmétique virgule fixe
Implémentation optimale de filtres linéaires en arithmétique virgule fixeImplémentation optimale de filtres linéaires en arithmétique virgule fixe
Implémentation optimale de filtres linéaires en arithmétique virgule fixe
 
Initiation au code : Ateliers en C# (applications desktop et mobile native)
Initiation au code : Ateliers en C# (applications desktop et mobile native)Initiation au code : Ateliers en C# (applications desktop et mobile native)
Initiation au code : Ateliers en C# (applications desktop et mobile native)
 
Corrige exercices pascal_fenni_2018
Corrige exercices pascal_fenni_2018Corrige exercices pascal_fenni_2018
Corrige exercices pascal_fenni_2018
 
09 big data mapreduce
09 big data mapreduce09 big data mapreduce
09 big data mapreduce
 

Destaque

Destaque (7)

Transformaciones lineales
Transformaciones linealesTransformaciones lineales
Transformaciones lineales
 
Waardig Organiseren Artikel
Waardig Organiseren ArtikelWaardig Organiseren Artikel
Waardig Organiseren Artikel
 
Camilacjd
CamilacjdCamilacjd
Camilacjd
 
Certingresos1
Certingresos1Certingresos1
Certingresos1
 
Conexión a bases de datos
Conexión a bases de datosConexión a bases de datos
Conexión a bases de datos
 
C:\Fakepath\Christie
C:\Fakepath\ChristieC:\Fakepath\Christie
C:\Fakepath\Christie
 
Estrategias competitivas básicas
Estrategias competitivas básicasEstrategias competitivas básicas
Estrategias competitivas básicas
 

Semelhante a Lect14 dev2

C1 - Langage C - ISIMA - Première partie
C1 - Langage C - ISIMA - Première partieC1 - Langage C - ISIMA - Première partie
C1 - Langage C - ISIMA - Première partieLoic Yon
 
Algorithmique Amp Programmation (R Sum
Algorithmique  Amp  Programmation (R SumAlgorithmique  Amp  Programmation (R Sum
Algorithmique Amp Programmation (R SumAmy Isleb
 
09 big data mapreduce
09 big data mapreduce09 big data mapreduce
09 big data mapreducePatrick Bury
 
Cours C Avancé chapitre 2 et chapitre.pdf
Cours C Avancé  chapitre 2 et chapitre.pdfCours C Avancé  chapitre 2 et chapitre.pdf
Cours C Avancé chapitre 2 et chapitre.pdfc79024186
 
Chap 2--POO avec JAVA.pdf
Chap 2--POO avec JAVA.pdfChap 2--POO avec JAVA.pdf
Chap 2--POO avec JAVA.pdframadanmahdi
 
cours-5.1.pdf
cours-5.1.pdfcours-5.1.pdf
cours-5.1.pdfGonnaBe1
 
C++11 en 12 exemples simples
C++11 en 12 exemples simplesC++11 en 12 exemples simples
C++11 en 12 exemples simplesPethrvs
 
Formation C# - Cours 2 - Programmation procédurale
Formation C# - Cours 2 - Programmation procéduraleFormation C# - Cours 2 - Programmation procédurale
Formation C# - Cours 2 - Programmation procéduralekemenaran
 
Chapitre 3 tableaux et pointeurs en C
Chapitre 3 tableaux et pointeurs en CChapitre 3 tableaux et pointeurs en C
Chapitre 3 tableaux et pointeurs en CAbdelouahed Abdou
 
Interception de signal avec dump de la pile d'appel
Interception de signal avec dump de la pile d'appelInterception de signal avec dump de la pile d'appel
Interception de signal avec dump de la pile d'appelThierry Gayet
 
Cours de C++ / Tronc commun deuxième année ISIMA
Cours de C++ / Tronc commun deuxième année ISIMACours de C++ / Tronc commun deuxième année ISIMA
Cours de C++ / Tronc commun deuxième année ISIMALoic Yon
 
resume algo 2023.pdf
resume algo 2023.pdfresume algo 2023.pdf
resume algo 2023.pdfsalah fenni
 

Semelhante a Lect14 dev2 (20)

C1 - Langage C - ISIMA - Première partie
C1 - Langage C - ISIMA - Première partieC1 - Langage C - ISIMA - Première partie
C1 - Langage C - ISIMA - Première partie
 
C++ 11/14
C++ 11/14C++ 11/14
C++ 11/14
 
Algorithmique Amp Programmation (R Sum
Algorithmique  Amp  Programmation (R SumAlgorithmique  Amp  Programmation (R Sum
Algorithmique Amp Programmation (R Sum
 
09 big data mapreduce
09 big data mapreduce09 big data mapreduce
09 big data mapreduce
 
Google Developer Group (GDG) Aix-Marseille #1 (27/08/2018)
Google Developer Group (GDG) Aix-Marseille #1 (27/08/2018)Google Developer Group (GDG) Aix-Marseille #1 (27/08/2018)
Google Developer Group (GDG) Aix-Marseille #1 (27/08/2018)
 
Cours C Avancé chapitre 2 et chapitre.pdf
Cours C Avancé  chapitre 2 et chapitre.pdfCours C Avancé  chapitre 2 et chapitre.pdf
Cours C Avancé chapitre 2 et chapitre.pdf
 
Theme 6
Theme 6Theme 6
Theme 6
 
Chap 2--POO avec JAVA.pdf
Chap 2--POO avec JAVA.pdfChap 2--POO avec JAVA.pdf
Chap 2--POO avec JAVA.pdf
 
Algo poo ts
Algo poo tsAlgo poo ts
Algo poo ts
 
Tour C++
Tour C++Tour C++
Tour C++
 
Theme 7
Theme 7Theme 7
Theme 7
 
cours-5.1.pdf
cours-5.1.pdfcours-5.1.pdf
cours-5.1.pdf
 
TAD (1).pptx
TAD (1).pptxTAD (1).pptx
TAD (1).pptx
 
C++11 en 12 exemples simples
C++11 en 12 exemples simplesC++11 en 12 exemples simples
C++11 en 12 exemples simples
 
Formation C# - Cours 2 - Programmation procédurale
Formation C# - Cours 2 - Programmation procéduraleFormation C# - Cours 2 - Programmation procédurale
Formation C# - Cours 2 - Programmation procédurale
 
Chapitre 3 tableaux et pointeurs en C
Chapitre 3 tableaux et pointeurs en CChapitre 3 tableaux et pointeurs en C
Chapitre 3 tableaux et pointeurs en C
 
Interception de signal avec dump de la pile d'appel
Interception de signal avec dump de la pile d'appelInterception de signal avec dump de la pile d'appel
Interception de signal avec dump de la pile d'appel
 
Cours de C++ / Tronc commun deuxième année ISIMA
Cours de C++ / Tronc commun deuxième année ISIMACours de C++ / Tronc commun deuxième année ISIMA
Cours de C++ / Tronc commun deuxième année ISIMA
 
resume algo 2023.pdf
resume algo 2023.pdfresume algo 2023.pdf
resume algo 2023.pdf
 
POO-chapitre2.pptx
POO-chapitre2.pptxPOO-chapitre2.pptx
POO-chapitre2.pptx
 

Último

PIE-A2-P 5- Supports stagiaires.pptx.pdf
PIE-A2-P 5- Supports stagiaires.pptx.pdfPIE-A2-P 5- Supports stagiaires.pptx.pdf
PIE-A2-P 5- Supports stagiaires.pptx.pdfRiDaHAziz
 
Pas de vagues. pptx Film français
Pas de vagues.  pptx   Film     françaisPas de vagues.  pptx   Film     français
Pas de vagues. pptx Film françaisTxaruka
 
Apprendre avec des top et nano influenceurs
Apprendre avec des top et nano influenceursApprendre avec des top et nano influenceurs
Apprendre avec des top et nano influenceursStagiaireLearningmat
 
Faut-il avoir peur de la technique ? (G. Gay-Para)
Faut-il avoir peur de la technique ? (G. Gay-Para)Faut-il avoir peur de la technique ? (G. Gay-Para)
Faut-il avoir peur de la technique ? (G. Gay-Para)Gabriel Gay-Para
 
Bibdoc 2024 - L’Éducation aux Médias et à l’Information face à l’intelligence...
Bibdoc 2024 - L’Éducation aux Médias et à l’Information face à l’intelligence...Bibdoc 2024 - L’Éducation aux Médias et à l’Information face à l’intelligence...
Bibdoc 2024 - L’Éducation aux Médias et à l’Information face à l’intelligence...Bibdoc 37
 
Bibdoc 2024 - Les maillons de la chaine du livre face aux enjeux écologiques.pdf
Bibdoc 2024 - Les maillons de la chaine du livre face aux enjeux écologiques.pdfBibdoc 2024 - Les maillons de la chaine du livre face aux enjeux écologiques.pdf
Bibdoc 2024 - Les maillons de la chaine du livre face aux enjeux écologiques.pdfBibdoc 37
 
DIGNITAS INFINITA - DIGNITÉ HUMAINE; déclaration du dicastère .pptx
DIGNITAS INFINITA - DIGNITÉ HUMAINE; déclaration du dicastère .pptxDIGNITAS INFINITA - DIGNITÉ HUMAINE; déclaration du dicastère .pptx
DIGNITAS INFINITA - DIGNITÉ HUMAINE; déclaration du dicastère .pptxMartin M Flynn
 
Bernard Réquichot.pptx Peintre français
Bernard Réquichot.pptx   Peintre françaisBernard Réquichot.pptx   Peintre français
Bernard Réquichot.pptx Peintre françaisTxaruka
 
Vulnérabilité numérique d’usage : un enjeu pour l’aide à la réussitepdf
Vulnérabilité numérique d’usage : un enjeu pour l’aide à la réussitepdfVulnérabilité numérique d’usage : un enjeu pour l’aide à la réussitepdf
Vulnérabilité numérique d’usage : un enjeu pour l’aide à la réussitepdfSylvianeBachy
 
Chana Orloff.pptx Sculptrice franco-ukranienne
Chana Orloff.pptx Sculptrice franco-ukranienneChana Orloff.pptx Sculptrice franco-ukranienne
Chana Orloff.pptx Sculptrice franco-ukranienneTxaruka
 
PIE-A2-P4-support stagiaires sept 22-validé.pdf
PIE-A2-P4-support stagiaires sept 22-validé.pdfPIE-A2-P4-support stagiaires sept 22-validé.pdf
PIE-A2-P4-support stagiaires sept 22-validé.pdfRiDaHAziz
 
La Base unique départementale - Quel bilan, au bout de 5 ans .pdf
La Base unique départementale - Quel bilan, au bout de 5 ans .pdfLa Base unique départementale - Quel bilan, au bout de 5 ans .pdf
La Base unique départementale - Quel bilan, au bout de 5 ans .pdfbdp12
 
Bibdoc 2024 - Ecologie du livre et creation de badge.pdf
Bibdoc 2024 - Ecologie du livre et creation de badge.pdfBibdoc 2024 - Ecologie du livre et creation de badge.pdf
Bibdoc 2024 - Ecologie du livre et creation de badge.pdfBibdoc 37
 
Potentiel du Maroc en Produits du Terroir et Stratégie Adoptée pour le dévelo...
Potentiel du Maroc en Produits du Terroir et Stratégie Adoptée pour le dévelo...Potentiel du Maroc en Produits du Terroir et Stratégie Adoptée pour le dévelo...
Potentiel du Maroc en Produits du Terroir et Stratégie Adoptée pour le dévelo...NaimDoumissi
 
Présentation - Initiatives - CECOSDA - OIF - Fact Checking.pptx
Présentation - Initiatives - CECOSDA - OIF - Fact Checking.pptxPrésentation - Initiatives - CECOSDA - OIF - Fact Checking.pptx
Présentation - Initiatives - CECOSDA - OIF - Fact Checking.pptxJCAC
 
Pas de vagues. pptx Film français
Pas de vagues.  pptx      Film   françaisPas de vagues.  pptx      Film   français
Pas de vagues. pptx Film françaisTxaruka
 
Cours de Management des Systèmes d'information
Cours de Management des Systèmes d'informationCours de Management des Systèmes d'information
Cours de Management des Systèmes d'informationpapediallo3
 

Último (18)

PIE-A2-P 5- Supports stagiaires.pptx.pdf
PIE-A2-P 5- Supports stagiaires.pptx.pdfPIE-A2-P 5- Supports stagiaires.pptx.pdf
PIE-A2-P 5- Supports stagiaires.pptx.pdf
 
Pas de vagues. pptx Film français
Pas de vagues.  pptx   Film     françaisPas de vagues.  pptx   Film     français
Pas de vagues. pptx Film français
 
Apprendre avec des top et nano influenceurs
Apprendre avec des top et nano influenceursApprendre avec des top et nano influenceurs
Apprendre avec des top et nano influenceurs
 
Faut-il avoir peur de la technique ? (G. Gay-Para)
Faut-il avoir peur de la technique ? (G. Gay-Para)Faut-il avoir peur de la technique ? (G. Gay-Para)
Faut-il avoir peur de la technique ? (G. Gay-Para)
 
Bibdoc 2024 - L’Éducation aux Médias et à l’Information face à l’intelligence...
Bibdoc 2024 - L’Éducation aux Médias et à l’Information face à l’intelligence...Bibdoc 2024 - L’Éducation aux Médias et à l’Information face à l’intelligence...
Bibdoc 2024 - L’Éducation aux Médias et à l’Information face à l’intelligence...
 
Bulletin des bibliotheques Burkina Faso mars 2024
Bulletin des bibliotheques Burkina Faso mars 2024Bulletin des bibliotheques Burkina Faso mars 2024
Bulletin des bibliotheques Burkina Faso mars 2024
 
Bibdoc 2024 - Les maillons de la chaine du livre face aux enjeux écologiques.pdf
Bibdoc 2024 - Les maillons de la chaine du livre face aux enjeux écologiques.pdfBibdoc 2024 - Les maillons de la chaine du livre face aux enjeux écologiques.pdf
Bibdoc 2024 - Les maillons de la chaine du livre face aux enjeux écologiques.pdf
 
DIGNITAS INFINITA - DIGNITÉ HUMAINE; déclaration du dicastère .pptx
DIGNITAS INFINITA - DIGNITÉ HUMAINE; déclaration du dicastère .pptxDIGNITAS INFINITA - DIGNITÉ HUMAINE; déclaration du dicastère .pptx
DIGNITAS INFINITA - DIGNITÉ HUMAINE; déclaration du dicastère .pptx
 
Bernard Réquichot.pptx Peintre français
Bernard Réquichot.pptx   Peintre françaisBernard Réquichot.pptx   Peintre français
Bernard Réquichot.pptx Peintre français
 
Vulnérabilité numérique d’usage : un enjeu pour l’aide à la réussitepdf
Vulnérabilité numérique d’usage : un enjeu pour l’aide à la réussitepdfVulnérabilité numérique d’usage : un enjeu pour l’aide à la réussitepdf
Vulnérabilité numérique d’usage : un enjeu pour l’aide à la réussitepdf
 
Chana Orloff.pptx Sculptrice franco-ukranienne
Chana Orloff.pptx Sculptrice franco-ukranienneChana Orloff.pptx Sculptrice franco-ukranienne
Chana Orloff.pptx Sculptrice franco-ukranienne
 
PIE-A2-P4-support stagiaires sept 22-validé.pdf
PIE-A2-P4-support stagiaires sept 22-validé.pdfPIE-A2-P4-support stagiaires sept 22-validé.pdf
PIE-A2-P4-support stagiaires sept 22-validé.pdf
 
La Base unique départementale - Quel bilan, au bout de 5 ans .pdf
La Base unique départementale - Quel bilan, au bout de 5 ans .pdfLa Base unique départementale - Quel bilan, au bout de 5 ans .pdf
La Base unique départementale - Quel bilan, au bout de 5 ans .pdf
 
Bibdoc 2024 - Ecologie du livre et creation de badge.pdf
Bibdoc 2024 - Ecologie du livre et creation de badge.pdfBibdoc 2024 - Ecologie du livre et creation de badge.pdf
Bibdoc 2024 - Ecologie du livre et creation de badge.pdf
 
Potentiel du Maroc en Produits du Terroir et Stratégie Adoptée pour le dévelo...
Potentiel du Maroc en Produits du Terroir et Stratégie Adoptée pour le dévelo...Potentiel du Maroc en Produits du Terroir et Stratégie Adoptée pour le dévelo...
Potentiel du Maroc en Produits du Terroir et Stratégie Adoptée pour le dévelo...
 
Présentation - Initiatives - CECOSDA - OIF - Fact Checking.pptx
Présentation - Initiatives - CECOSDA - OIF - Fact Checking.pptxPrésentation - Initiatives - CECOSDA - OIF - Fact Checking.pptx
Présentation - Initiatives - CECOSDA - OIF - Fact Checking.pptx
 
Pas de vagues. pptx Film français
Pas de vagues.  pptx      Film   françaisPas de vagues.  pptx      Film   français
Pas de vagues. pptx Film français
 
Cours de Management des Systèmes d'information
Cours de Management des Systèmes d'informationCours de Management des Systèmes d'information
Cours de Management des Systèmes d'information
 

Lect14 dev2

  • 1. INFORMATIQUE III DEVOIR SURVEIEE 2 Notes 18 - 20 p. ( excellent 6); 15 – 17 p . ( tr è s bien 5); 12 – 14 p. (bien 4); 10 – 11 p. (passable 3)
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. #include<stdio.h> #include<stdlib.h> #include <string.h> #define NUM 2 void output(char **p,int k); void sort(char **p,int k); char ** insert(char **ptext,int *n_l); int main(void) { int n_l; char **ptext; ptext=insert(ptext,&n_l); printf(&quot;%d chaines (noms) ont lus&quot;,n_l); printf(&quot;Liste originale des noms:&quot;); output(ptext,n_l); sort(ptext,n_l); printf(&quot;Liste des nom tries:&quot;); output(ptext,n_l); free(ptext); return(0); }
  • 12. char ** insert(char **ptext,int *n_l) { char *p; FILE *fp; int n_el=NUM ; *n_l=0; char buf[SIZE]; if((fp=fopen(&quot;test.txt&quot;, &quot;r&quot;)) == NULL) { printf(&quot;Fichier n'est pas ouvert.&quot;); exit(1); } if((ptext=(char **) malloc ( n_el *sizeof(char *)))==NULL){ printf(&quot;Erreur!&quot;); exit(1); }
  • 13. do{ if( fgets(buf,sizeof(buf),fp)== NULL){ printf(&quot;Erreur lecture!&quot;); exit(1); } if((p=(char*)malloc( sizeof(char)*(strlen(buf)+1)))== NULL){ printf(&quot;Erreur!&quot;); exit(1); } strcpy(p,buf); if(*n_l==n_el) { n_el+=NUM ; if (ptext=(char**) realloc (ptext, n_el *sizeof(char*)))==NULL){ printf(&quot;Erreur!&quot;); exit(1); } } ptext[(*n_l)++]=p; } while(!feof(fp)); strcat(*(ptext+*n_l-1),&quot;&quot;); return ptext; }
  • 14. void output(char **p,int k) { int j; for(j=0;j<k;j++) printf(&quot;%s&quot;,*(p+j)); } void sort(char **p,int k) { int j,flag; char st[80]; do{ flag=0; for(j=0;j<k-1;j++) if(strcmp(*(p+j),*(p+j+1))>0){ flag=1; strcpy(st,*(p+j)); strcpy(*(p+j),*(p+j+1)); strcpy(*(p+j+1),st); } } while(flag); }
  • 15.  
  • 16.
  • 17. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <memory.h> #define NBR 5 typedef struct { char name[20]; float averageMark; }STUDENT; void myMenu(); STUDENT * addStudentFromKey(short *); void inputStudent(STUDENT*); void printArray(STUDENT *,short ); FILE *writeStructFile(STUDENT *,short); void sortArray(STUDENT *,short); int sortName(const void *,const void *); int sortAverageMark(const void *,const void *); void SearchFile(FILE *);
  • 18. int main() { myMenu(); return 0; } ///////////////////////////////////////////////// void myMenu() { FILE *fp; short a,i; STUDENT *array; do { printf(&quot;1.Creer tableau dynamique des structures - entrees par clavier 2.Afficher le tableau 3.Ecrire le tableau dans un fichier binaire 4.Trier le tableau dynamique des structures 5.Chercher dans le fichier les etudiants avec notes >=5.50&ecrire 6.Fin Votre choix :&quot;); scanf(&quot;%d&quot;,&a);
  • 19. switch(a) { case 1:array=addStudentFromKey(&i);break; case 2:printArray(array,i);break; case 3:fp=writeStructFile(array,i);break; case 4:sortArray(array,i); break; case 5:SearchFile(fp); } }while(a!=6); free(array); }
  • 20. STUDENT* addStudentFromKey(short *i) { STUDENT *array,a; char word[4]; int n=NBR; *i=0; array=(STUDENT*)malloc(n*sizeof(STUDENT)); if(array == NULL) exit(1); while(printf(&quot;La structure suivante dans le tableau? - (oui/no)&quot;), fflush(stdin),strcmp(gets(word),&quot;oui&quot;)==0) { if(*i == n) { n=n*2; array=(STUDENT*)realloc(array,n*sizeof(STUDENT)); if(array == NULL) exit(1); } printf(&quot;ETUDIANT NOMBRE %d: &quot;,*i+1); inputStudent(&a); memcpy(&array[*i],&a,sizeof(STUDENT)); (*i)++; } return array; }
  • 21. void inputStudent(STUDENT *a) { fflush(stdin); printf(&quot;Entrer le nom:&quot;); gets(a->name); printf(&quot;Entrer la note moyenne:&quot;); scanf(&quot;%f&quot;,&a->averageMark); } ////////////////////////////////////////////////////////////////////////////////////////// void printArray(STUDENT *array,short n) { int i; printf(&quot;Les elements du tableau dynamique ETUDIANT NOMBRE ETUDIANT NOM ETUDIANT NOTE MOYENNE&quot;); for(i=0;i<n;i++) printf(&quot;%-18d %-28s %-10.2f&quot;,i+1,array[i].name,array[i].averageMark); }
  • 22. FILE* writeStructFile(STUDENT *array,short n) { FILE *fp; char fname[15]; short i; puts(&quot;Entrer le nom du fichier pour ecrire&quot;); fflush(stdin); gets(fname); fp=fopen(fname,&quot;w+b&quot;); if(fp==NULL) { printf( &quot;Problem d'ouverture&quot; ); exit(1); } for(i=0;i<n;i++) fwrite(&array[i],sizeof(STUDENT),1,fp); return(fp); }
  • 23. void sortArray(STUDENT *array,short n) { short k; printf(&quot;Choix du tri :0 - par nom;1 - par note moyenne&quot;); fflush(stdin); scanf(&quot;%d&quot;,&k); qsort((void*)array,n,sizeof(STUDENT),k?sortAverageMark:sortName); } ////////////////////////////////////////////////////////////////////////////// int sortName(const void *pa,const void *pb) { char x; STUDENT*a=(STUDENT*)pa; STUDENT*b=(STUDENT*)pb; x=strcmp(a->name,b->name); if(x>0) return 1; else if(x<0) return -1; else return 0; }
  • 24. int sortAverageMark(const void *pa,const void *pb) { STUDENT*a=(STUDENT*)pa; STUDENT*b=(STUDENT*)pb; if(a->averageMark > b->averageMark) return 1; else if(a->averageMark < b->averageMark) return -1; else return 0; }
  • 25. void SearchFile(FILE *fp) { FILE *fp_new; char fname_new[15]; STUDENT temp; rewind(fp); puts(&quot;Entrer le nom du fichier pour ecrire&quot;); fflush(stdin); gets(fname_new); fp_new=fopen(fname_new,&quot;w+b&quot;); if(fp_new==NULL) { printf( &quot;Problem problem d'ouverture&quot; ); exit(1); } while(fread(&temp,sizeof(STUDENT),1,fp)==1) if(temp.averageMark >= 5.50) fwrite(&temp,sizeof(STUDENT),1,fp_new); rewind(fp_new); while(fread(&temp,sizeof(STUDENT),1,fp_new)==1) printf(&quot;%-28s %-10.2f&quot;,temp.name,temp.averageMark); fclose(fp); fclose(fp_new); }
  • 26.  
  • 27.  
  • 28.  
  • 29.  
  • 30.  
  • 31.  
  • 32.
  • 33. ppch[0] word0 ppch[1] ppch[2] word1 word2 ppch[i] ppch[n] wordn char **ppch
  • 34. #include <stdio.h> #include <string.h> #include <stdlib.h> #define NUM 2 void prt(char **ppch,int n){ int i; for(i=0;i<n;i++){ printf(&quot;%s&quot;,ppch[i]); } } int exist(char **ppch, int n, char *w){ int i; for(i=0; i<n;i++){ if(!strcmp(ppch[i],w)) return 1; } return 0; }
  • 35. char ** insert(char **ppch, int *n_w,int *n_el, char *w){ char *p; if ((p = (char *)malloc(sizeof(char)*(strlen(w)+1)))== NULL){ return NULL; } strcpy(p, w); if(*n_w == *n_el){ *n_el+=NUM; if ( (ppch = (char **)realloc( ppch,*n_el*sizeof(char*)))==NULL) { return NULL; } } ppch[(*n_w)++]= p; return ppch; }
  • 36. void sort(char **ppch, int n_w){ int i,ok; char *help; do { ok=1; for(i=0;i<n_w-1;i++){ if(strcmp(ppch[i],ppch[i+1])>0){ help=ppch[i]; ppch[i]=ppch[i+1]; ppch[i+1]=help; ok=0; } } }while (!ok); } void free_m(char **ppch,int n_words){ int i; for(i=0;i<n_words;i++){ free(ppch[i]); } free(ppch); }
  • 37. int main(){ int n_words=0, n_el=NUM ; char buf[251], **ppch; FILE *f; if((f=fopen(&quot;b.txt&quot;,&quot;rt&quot;))==NULL){ printf (&quot;The file cannot be read&quot;); return 2; } if ( (ppch = (char **)malloc( n_el*sizeof(char*)))== NULL){ printf(&quot;No memory&quot;); return 3; } while(!feof(f)) { if( fscanf(f,&quot;%250s&quot;,buf) == EOF){ break; } if(!exist(ppch,n_words,buf)){ if((ppch=insert(ppch, &n_words,&n_el,buf))==NULL){ printf(&quot;No memory&quot;); return 3; } } } sort(ppch, n_words); prt(ppch, n_words); free_m(ppch,n_words); return 0; } alfa alfa tita gama beta alfa beta gama tita