int i=0;
int numProgs=0;
char* input[500];
char line[500];
FILE *file;
file = fopen(argv[1], "r");
while(fgets(line, sizeof line, file)!=NULL) {
/*check to be sure reading correctly
add each filename into array of input*/
input[i] = (char*)malloc(strlen(line)+1);
strcpy(input[i],line);
printf("%s",input[i]);/*it gives the hole line with\n*/
i++;
/*count number of input in file*/
numProgs++;
}
/*check to be sure going into array correctly*/
fclose(file);
我不知道每行的输入txt的大小,所以我需要动态地做 . 我需要使用char * input []这种类型的数组,我还需要使用int numProgs保存行号 . 输入文本文件有多行,每行都有未知的字符大小 .
1 回答