テキストファイルから単語の配列を作成しようとしています。私は値を正しく出力するためにそれを得ることができますが、私は実際に使用できる配列が必要です。私がこの配列を作った後は、それぞれの長さを数えるなど、私が保存した言葉にさまざまなことをしなければなりません。今のところ私は実際に作業できる配列を作るのに役立つだけです。C TexFileから配列を作成する
# 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]);
//
//}
あなたが実際に質問をしていなかった(ここではあなたの配列です)。 – melpomene
*実際に*で動作する*配列は何ですか? – Arash
1) 'strcat(argv [1]、" _ 1.txt ");'これはできません。 – BLUEPIXY