텍스트 파일에서 단어 배열을 만들려고합니다. 값을 올바르게 출력 할 수는 있지만 실제로 작업 할 수있는 배열이 필요합니다. 이 배열을 얻은 후에는 각 단어 길이를 세는 것과 같이 내가 저장 한 단어에 대해 여러 가지 일을해야합니다. 현재로서는 실제로 작업 할 수있는 배열을 만드는 데 도움이 필요합니다. 이 코드는 컴파일되지 않았다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