1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| #include "eltprim.h"
#include "dicoprim.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define MAX 1000
int main (void) {
int cpt=0,i=1,y=0;
char temp[50],tmp[50];
char buffer[MAX];
char sep[] =" ";
FILE *fichier;
char *nomfichier;
char* mots;
char **pp_mots;
printf("Indiquez l'emplacement et le nom du fichier a verifier (ex:C:\\..\\nom.txt)\n");
gets(temp);
nomfichier=(char*)malloc((strlen(temp)+1)*sizeof(char));
strcpy(nomfichier,temp);
fichier=fopen(nomfichier, "r+");
if (fichier==NULL){
printf("Probleme avec l'ouverture du fichier");
}
else{
while (feof(fichier)==0){
fscanf(fichier,"%s",tmp);
cpt++;}
printf("Il y a %d mots\n",cpt-1);
rewind(fichier);
pp_mots = malloc ((cpt)*sizeof (char*));
fgets(buffer,MAX,fichier) ;
printf("%s\n", buffer);
mots = strtok(buffer, sep);
while ( mots!= NULL ) {
printf("%d : %s\n",i,mots);
i++;
mots = strtok(NULL, sep);
pp_mots[y] = strdup(mots);
y++;
}
}
printf("Mot numero 2 : %s",pp_mots[2]); |