J'essaie de créer un tableau de mots à partir d'un fichier texte. Je suis capable de l'imprimer correctement, mais j'ai besoin d'un tableau avec lequel je peux travailler. Après avoir ce tableau, je dois faire différentes choses avec les mots que j'ai stockés, comme compter chacun leur longueur. Pour l'instant j'ai juste besoin d'aide pour faire un tableau avec lequel je peux réellement travailler.C Création d'un tableau à partir de TexFile
Voici le code:
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
int main (int argc, char* argv[]){
// First Read in First novel File
FILE *fp;
char *ProgFile;
// Variables for Parsing
int i = 0;
int j=0;
char *cp;
char *bp;
char line[255];
char *array[5000];
int x;
int wordCount=0;
int wordCountPerNovel;
// Adjusting the file name to include txt and corresponding number
strcat(argv[1],"_1.txt");
ProgFile = argv[1];
// Open Each File
fp=fopen(ProgFile,"r");
if(fp==NULL)printf("error");
else printf("bin file loaded: '%s'",ProgFile);
// Now begin analysing
// Part 1
// Parse Entire Document into Array of Strings
while (fgets(line, sizeof(line), fp) != NULL) {
bp = line;
while (1) {
cp = strtok(bp, ",.!?<97> \n");
bp = NULL;
if (cp == NULL)break;
array[i++] = cp;
printf("Check print - word %i:%s:\n",i-1, cp);
}
}
// At this point i is the last word that was iterated, -1 since it breaks out after being added
// This gets total words of all novels
wordCount=wordCount+(i-1);
printf("\nTotal words %i\n",wordCount);
// Find Total number of letters
//for (i=1;i<15;i++){
// printf("My value: %s \n",finalArrayWord[i]);
//
//}
Vous ne demandez pas vraiment une question. – melpomene
Qu'est-ce qu'un tableau * avec lequel je peux réellement travailler *? – Arash
1) 'strcat (argv [1]," _ 1.txt ");' Ce n'est pas possible. – BLUEPIXY