Skip to content
Snippets Groups Projects
Commit ada62e2e authored by Mazouzi's avatar Mazouzi
Browse files

fin tp

parent 1ecb2dc5
No related branches found
No related tags found
No related merge requests found
No preview for this file type
File deleted
No preview for this file type
File added
File added
TARGET=tp6
CFLAGS=-g -W -Wall -Wextra
default: $(TARGET)
listechaines.o: listechaines.c listechaines.h
gcc $(CFLAGS) -c listechaines.c
tp6.o : tp6.c listechaines.h
gcc $(CFLAGS) -c tp6.c
$(TARGET): $(TARGET).o listechaines.o
gcc tp6.o listechaines.o -o $(TARGET)
clean:
rm -f *.o *~ $(TARGET)
/*
* Acompagnement du TP, code exemple pour vous aider.
*/
//ajout d'un mot dans une liste chainee triée
void ajout_alphab(struct cell ** pl, char * mot)
{
// liste vide ou mot < mot prochain => ajout en tête
if ( (*pl == NULL) || (strcmp(mot, (*pl)->val) < 0) )
{
ajout_tete(pl,mot);
}
else
{
// mot > mot prochain => ajouter après dans la liste
if (strcmp(mot, (*pl)->val) > 0)
{
ajout_alphab(&(*pl)->suiv,mot);
}
//else => mot déjà dans la liste, ne rien faire?
}
}
//construit une liste triee a partir d'un fichier
void charge_fichier(FILE * fp, struct cell ** pl)
{
char mot[MAXSIZE];
//Nb d'elements à lire dans chaque fscanf
const int NB_A_LIRE = 1;
//`man fscanf` pour comprendre les valeurs de retour!!!
while (fscanf(fp, "%s", mot) == NB_A_LIRE)
{
ajout_alphab(pl, mot);
}
//On peut tester la bonne ou mauvaise terminaison de la lecture
if(feof(fp)) printf("Fin normal de lecture\n");
if(ferror(fp)) printf("ERREUR de lecture\n");
}
#include "listechaines.h"
......@@ -12,8 +13,8 @@ void afficher_liste(struct cell* liste){
printf("Voici la liste:\n");
while (temp != NULL){
printf("%s\n", temp->c.val);
temp = temp->suivant;
printf("%s\n", temp->val);
temp = temp->suiv;
}
}
......@@ -28,15 +29,15 @@ void ajout_tete(struct cell **pliste, char *c){
}
int supp_tete(struct cell **pliste){
void supp_tete(struct cell **pliste){
if (*pliste == NULL)
return 0;
return;
struct cell *temp;
temp = *pliste;
*pliste = (*pliste)->suivant;
*pliste = (*pliste)->suiv;
free(temp);
return 1;
return;
}
......@@ -87,17 +88,17 @@ void charge_fichier(FILE * fp, struct cell ** pl)
bool appartient(struct cell *liste, char *c){
if (liste == NULL) return 0;
if (!strcmp(liste->val,c)) return 1;
return (appartient(liste->suiv));
return (appartient(liste->suiv,c));
}
int taille(struct cell *liste){
if (liste == NULL) return 0;
return taille(liste->suiv)+1
return taille(liste->suiv)+1;
}
int main(){
File added
Mathilde
Pauline
Paul
Edward
Kevin
Louis
Najet
Marine
Yoan
Liam
Arnaud
Janet
Georges
Benoit
#include <stdio.h>
#include <stdlib.h>
#include "listechaines.h"
int main(){
struct cell *liste;
liste = NULL;
FILE *fd;
fd = fopen("text.txt","r");
charge_fichier(fd,&liste);
afficher_liste(liste);
fclose(fd);
return 0;
}
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment