将数字存储为(x,y)从特定点的文件中进行控制

我有一个实例文件 ,我需要以2Darrays系统的forms存储NUM_PT和所有相应的坐标( 个人选择,以便我可以轻松访问它们 )。 我能够检索NUM_PT但我仍然在阅读连续的坐标到我的数组中。

这是我做的

/* Assignment 2 */ #include  #include  #include  #include  #include  #define MAXS 256 int main(int argc, char *argv[]) { int num_pt; int inputfile = 0, outputfile = 0, i; for (i = 1; i  %s [-i inputfile [-o outputfile]]\n\n", argv[0]); exit(0); } FILE *fp; fp = fopen(argv[inputfile], "r"); int count = 0; if (fp == 0) { printf("\nCould not find %s\n", argv[inputfile]); exit(0); } char line[MAXS]; while (fgets(line, sizeof line, fp) != NULL) { if (count == 4) { fscanf(fp, "%d", &num_pt); break; } else count++; } int arr[num_pt][1]; while (fgets(line, sizeof line, fp) != NULL) { if (count == 5) { int k, j, cord; for (k = 0; k < num_pt; k++) { for (j = 0; j  0) { arr[k][j] = cord; j++; } } } } } fclose(fp) return 0; } 

检索NUM_PT后,我尝试将count重新初始化为5,因为坐标从文件中的** LINE 6 *开始。

来自编译器的错误 ubuntu bash脚本

语言:c99; 编译器:gcc

样本“将数字存储为(x,y)从文件中坐标”(最好不要修复阅读位置)

 #include  typedef struct point { int x, y; } Point; int readPoint(FILE *fp, Point *p); int readInt(FILE *fp, int *n); int main(void){ FILE *fp = fopen("instance10_001.txt", "r"); Point p; int MAX_X, MAX_Y; readPoint(fp, &p); MAX_X = px; MAX_Y = py; printf("MAX_X:%d, MAX_Y:%d\n", MAX_X, MAX_Y); int NUM_PT; readInt(fp, &NUM_PT); printf("NUM_PT:%d\n", NUM_PT); Point arr[NUM_PT]; for(int i = 0; i < NUM_PT; ++i){ readPoint(fp, &arr[i]); printf("Point(%d, %d)\n", arr[i].x, arr[i].y); } fclose(fp); } int readLine(FILE *fp, char *buff, int buff_size){ while(fgets(buff, buff_size, fp)){ if(*buff == '#' || *buff == '\n') continue; return 1; } return 0; } #define LINE_MAX 128 int readPoint(FILE *fp, Point *p){ char buff[LINE_MAX]; if(readLine(fp, buff, sizeof buff)){ return 2 == sscanf(buff, "%d %d", &p->x, &p->y); } return 0; } int readInt(FILE *fp, int *n){ char buff[LINE_MAX]; if(readLine(fp, buff, sizeof buff)){ return 1 == sscanf(buff, "%d", n); } return 0; }