目前我读入了一个文件,如下面的代码所示。但是,我希望能够输入文件名并以相同的方式处理该文件,我使用的是 Microsoft Visual C++ 2010 express。编码:
int main (int argc, char *argv[])
{
static const int MAX_FILE_ROWS = 10;
double lines[MAX_FILE_ROWS][4];
FILE *file = fopen("filename.txt", "r");
for (int i = 0; i < MAX_FILE_ROWS; i++){
if (feof(file))
break;
fscanf(file, "%lf %lf %lf %lf", &(lines[i][0]), &(lines[i][1]), &(lines[i][2]), &(lines[i][3]));
printf("%f %f %f %f\n", lines[i][0], lines[i][1], lines[i][2], lines[i][3]);
}
fclose(file);