Fichier séquentiel en C
rafale69300
Messages postés
84
Date d'inscription
Statut
Membre
Dernière intervention
-
rafale69300 Messages postés 84 Date d'inscription Statut Membre Dernière intervention -
rafale69300 Messages postés 84 Date d'inscription Statut Membre Dernière intervention -
Bonjour, voici mon problème je fais du C et on utilise les fichier séquentiels, j'ai des erreurs que je n'arrive pas à résoudre.
Mes 4 première procédure sont juste( fscanf & fprintf) je devrais les faire après avec fread et fwrite. Mais mes 3 dernières procédures ont des erreurs que je n'arrive pas à corriger. Merci par avance de votre aide.
Mes 4 première procédure sont juste( fscanf & fprintf) je devrais les faire après avec fread et fwrite. Mais mes 3 dernières procédures ont des erreurs que je n'arrive pas à corriger. Merci par avance de votre aide.
#include "client.h" #include <stdio.h> /* Premiere version : utilisation de fprintf, fscanf */ /*Cette procedure affiche le contenu du fichier*/ void lirefichierclient(void) { CLIENT enrclient; FILE *fclient; int temp; fclient=fopen("Client1.dat","r"); if(fclient!=NULL) { temp=fscanf(fclient,"%d %s %s",&enrclient.numcli,enrclient.nomcli,enrclient.coordcli); while(temp!=EOF) { printf("\n%d",enrclient.numcli); printf("\n%s",enrclient.nomcli); printf("\n%s",enrclient.coordcli); temp=fscanf(fclient,"%d %s %s", &enrclient.numcli,enrclient.nomcli,enrclient.coordcli); } fclose(fclient); } else { printf("\n Problème d'ouverture de fichier"); } } /*Cette procedure ajoute un client, a la fin du fichier*/ void creerfichierclient(void) { CLIENT enrclient; FILE *fclient; char rep[2]; fclient=fopen("Client1.dat","w"); if(fclient!=NULL) { do { printf("\nSaisir les données du client"); scanf("%d",&enrclient.numcli); scanf("%s",enrclient.nomcli); scanf("%s",enrclient.coordcli); fprintf(fclient,"%d %s %s\n",enrclient.numcli,enrclient.nomcli,enrclient.coordcli); printf("\nAutre saisie(o/n)?"); scanf("%s",rep); }while(rep[0]=='o'); fclose(fclient); } else { printf("\n Problème d'ouverture de fichier\n"); } } void initialisertableau(CLIENT Tclient[], int *pnbclient) { CLIENT enrclient; FILE *fclient; int temp,i; fclient=fopen("Client1.dat","r"); if(fclient!=NULL) { temp=fscanf(fclient,"%d %s %s",&enrclient.numcli,enrclient.nomcli,enrclient.coordcli); i=0; while(i<=MAXC-1 && temp!=EOF) { Tclient[i]=enrclient; printf("\n%d %s %s",Tclient[i].numcli,Tclient[i].nomcli,Tclient[i].coordcli); i++; temp=fscanf(fclient,"%d %s %s",&enrclient.numcli,enrclient.nomcli,enrclient.coordcli); } *pnbclient=i; fclose(fclient); } else { printf("\n Problème d'ouverture de fichier\n"); } } void sauvegardertableau(CLIENT Tclient[], int nbclient) { CLIENT enrclient; FILE *fclient; int i; fclient=fopen("Client1.dat","w"); for(i=0;i<nbclient;i++) { enrclient=Tclient[i]; fprintf(fclient,"%d %s %s\n",enrclient.numcli,enrclient.nomcli,enrclient.coordcli); } fclose(fclient); } void ajouterclient(CLIENT Tclient[], int *pnbclient) { char cli[50]; int num; char coord[50]; printf("Saisir le nom du Client \n"); scanf("%s",&cli); printf("Saisir le num du Client \n"); scanf("%d",&num); printf("Saisir les coords du Client \n"); scanf("%s",&coord); CLIENT enrclient; if(trouverclient(Tclient.nomcli,pnbclient,cli) == -1 || trouverclient(Tclient.numcli,pnbclient,num == -1)) { if(*pnbclient>0 && *pnbclient<MAXC) { Tclient[*pnbclient+1].nomcli=cli; Tclient[*pnbclient+1].numcli=num; Tclient[*pnbclient+1].coordcli=coord; pnbclient++; } else printf("Probleme d'indice \n"); } else printf(" Numero ou Nom du client deja existant \n"); } void supprimerclient(CLIENT Tclient[], int *pnbclient) { char cli[50]; int ind; int i; printf("Saisir le nom du Client \n"); scanf("%s",&cli); if(trouverclient(Tclient.nomcli,*pnbclient,cli)>0) { ind=trouverclient(Tclient.nomcli,*pnbclient,cli); if(*pnbclient>0 && *pnbclient<MAXC) { if(ind<=*pnbclient) { i=ind; while(i<pnbclient) { Tclient[i]=Tclient[i+1]; i=i++; } pnbclient--; } else printf(" Indice passé invalide \n"); } else printf(" Nombre effectif invalide \n"); } else printf("Client non trouvé "); } int trouverclient(CLIENT Tclient[], int nbclient, char nom[]) { int i; if(nbclient<=MAXC && nbclient>0) { i=1; while(i<=nbclient && Tclient[i]=!nom) { i++; } if( i<=nbclient) return i; else return -1; } else printf("Nombre effectif invalide \n"); }
A voir également:
- Fichier séquentiel en C
- Fichier bin - Guide
- Fichier epub - Guide
- Fichier rar - Guide
- Comment réduire la taille d'un fichier - Guide
- Fichier .dat - Guide
2 réponses
Salut,
ta fonction:
int trouverclient(CLIENT Tclient[], int nbclient, char nom[])
tu lui déclares en paramètre un tableau de structure de type client et quand tu l'appelles, tu lui transmets un char* (meme si Tclient.nomcli, je sai spas trop où cela pointe....)
trouverclient(Tclient.nomcli,pnbclient,cli).
J'ai pas regardé plus que cela mais j'espère ça pourra t'aider!!
@+
ta fonction:
int trouverclient(CLIENT Tclient[], int nbclient, char nom[])
tu lui déclares en paramètre un tableau de structure de type client et quand tu l'appelles, tu lui transmets un char* (meme si Tclient.nomcli, je sai spas trop où cela pointe....)
trouverclient(Tclient.nomcli,pnbclient,cli).
J'ai pas regardé plus que cela mais j'espère ça pourra t'aider!!
@+