Ich versuche, ein Array von Wörtern aus einer Textdatei zu erstellen. Ich kann es bekommen, um die Werte richtig auszudrucken, aber ich brauche ein Array, mit dem ich tatsächlich arbeiten kann. Nachdem ich dieses Array habe, muss ich verschiedene Dinge zu den Wörtern tun, die ich gespeichert habe, z. B. das Zählen jeder einzelnen Länge. Jetzt brauche ich nur Hilfe, um ein Array zu erstellen, mit dem ich tatsächlich arbeiten kann. HierC Erstellen eines Arrays aus TexFile
ist der 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]);
//
//}
Sie haben eigentlich nicht eine Frage stellen. – melpomene
Was ist ein * Array, mit dem ich tatsächlich arbeiten kann *? – Arash
1) 'strcat (argv [1]," _ 1.txt ");' Kann das nicht. – BLUEPIXY