之前的预期表达式(C编程语言)

时间:2013-12-10 19:39:41

标签: c scanf

我正在尝试将f指向的文件中的数据读入我的struct数组:r_a[], 但我收到expected expression before r_a"行上的错误fscanf()

头文件:

void setAsset(FILE *f);

  typedef struct rescue_asset{
      char callsign[31];
      char type;
      char location[31];
      double lat;
      double lng;
      double operational_speed;
      int maxDeployDuration;
      int lot_to_service;    
  }r_a[51];

c file:

#include "rescue_assets.h"
void setAsset(FILE * f)
{
    int i = 0;

    while (getchar() != EOF)
    {
        fscanf(f, "%s %c %s %f %f %f %d %d", &r_a[i].callsign, &r_a[i].type,
               &r_a[i].location, &r_a[i].lat, &r_a[i].lng, &r_a[i].operational_speed,
               &r_a[i].maxDeployDuration, &r_a[i].lot_to_service);

        ++i;
    }
}

1 个答案:

答案 0 :(得分:0)

typedef struct rescue_asset{
  char callsign[31];
  char type;
  char location[31];
  double lat;
  double lng;
  double operational_speed;
  int maxDeployDuration;
  int lot_to_service;
}r_a_t;

r_a_t r_a[51];

因为你必须使用一个不是类型的变量。另一件奇怪的事就是你的循环

while (getchar() != EOF)

你应该检查i< 51和fscanf返回值