My goal is to read a file, and save each elements in this file into a new array..
rewind(fp); ii = 0; while (!feof(fp)) {
ii ++;
fscanf(fp, "%s\n", filename_i);
fp_i = fopen(filename_i, "r");
if (fp_i == NULL) {
fprintf(stderr, "can't open input file %s \n", filename_i);
exit(1);
}
filename_ii[ii] = filename_i;
printf("%s, %d\n", filename_ii[ii],ii);
fclose(fp_i);
}
printf("a %s %d\n",filename_ii[9],DataSize[2]);
printf("a %s %d\n",filename_ii[1],DataSize[2]);
In while() function, my output is each elements, but I don't know why the last two printf() returns the same results, i.e, it seems like both filename_ii[1] and filename_ii[9] point the last element in the file. Does anyone have ideas about what's wrong in my code? Thank you~