Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionTAB[ind]->nom=strdup(nomlu);
#include <stdio.h> #include <stdlib.h> #include <string.h> #define REP_SIZE 30 typedef struct { char* nom; int nbtel; int tnum[3]; } Rep; int exists(Rep* tab[REP_SIZE], const char* name) { int i = 0; while (tab[i] != NULL && i < REP_SIZE) { if (strcmp(name, tab[i]->nom) == 0) return 1; ++i; } return 0; } int addRecord(Rep* tab[REP_SIZE], const char* name) { int i = 0; /* ** On recherche la premiere position libre */ while (tab[i] != NULL && i < REP_SIZE) ++i; if (i >= REP_SIZE) return 0; tab[i] = malloc(1 * sizeof(Rep)); tab[i]->nom = strdup(name); return 1; } void displayTab(Rep* tab[REP_SIZE]) { int i = 0; for (i = 0; tab[i] != NULL && i < REP_SIZE; ++i) printf("%s ", tab[i]->nom); printf("\n"); } void freeTab(Rep* tab[REP_SIZE]) { int i = 0; for (i = 0; tab[i] != NULL && i < REP_SIZE; ++i) { free(tab[i]->nom); free(tab[i]); } printf("\n"); } int main(void) { char nomlu[21] = {0}; Rep* tab[REP_SIZE] = {0}; int i = 0; while (nomlu[0] != '*') { printf("Entrez le nom :"); scanf("%s", nomlu); if (nomlu[0] == '*') break; if (exists(tab, nomlu)) printf("NOM DEJA ENREGISTRE\n"); else { if (addRecord(tab, nomlu)) printf("ENREGISTREMENT EFFECTUE %s\n", tab[i]->nom); else printf("ENREGISTREMENT RATE %s\n", nomlu); } } displayTab(tab); freeTab(tab); return 0; }