0

尝试使用 GCC 编译这个简短的 C 程序时,我收到以下错误:

expected ‘)’ before numeric constant
make: *** [file3_5.o] Error 1
stray ‘\210’ in program
stray ‘\227’ in program
stray ‘\342’ in program 

Eclipse (Juno) 将所有这些错误都指向一行代码:

while(fgets(line ,STRSIZE∗NFIELDS, fp))

使用以下语句进行编译:

gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"file3_5.d" -MT"file3_5.d" -o "file3_5.o" "../file3_5.c"

这是我要编译的程序:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define STRSIZE 100
#define NFIELDS 9
int main()
{
    char inputfile[]= "/home/ty/workspace/OpenCoursware_Exercises/Assign_   /stateoutflow0708.txt";
  /* define all of the fields */
  char state_code_org[STRSIZE];
  char country_code_org[STRSIZE];
  char state_code_dest[STRSIZE];
  char country_code_dest[STRSIZE];
  char state_abbrv[STRSIZE];
  char state_name[STRSIZE];
  char line[STRSIZE*NFIELDS];
  int return_num = 0;
  int exmpt_num=0;
  int aggr_agi= 0;
  long total=0;

  /* file related */
  int fields_read = 0;
  FILE* fp=fopen(inputfile,"r");
  if(fp==NULL)
  {
    fprintf(stderr, "Cannot open file\n");
    exit(-1);
  }
  /* skip first line */
  fgets(line, STRSIZE*NFIELDS,fp);
  /* print the header */
  printf ("%-30s,%6s\n","STATE","TOTAL");
  printf("---------------------------------------\n");
  while(fgets(line ,STRSIZE∗NFIELDS, fp))
  {
      /* parse the fields */
      fields_read=sscanf(line,"%s %s %s %s %s %s %d %d %d",
              state_code_org,
              country_code_org,
              state_code_dest,
              country_code_dest,
              state_abbrv,
              state_name,
              &return_num,
              &exmpt_num,
              &aggr_agi);
      if(strcmp(state_code_org, "\"25\"")==0)
      {
          printf("%-30s, %6d\n", state_name, aggr_agi);
          total += aggr_agi;
      }
  }
  /* print the header */
  printf(" ----------------------------------------\n");
  printf("%-30s,%6lu\n","TOTAL",total);
  fclose(fp);
  return 0;
 }
4

3 回答 3

3
于 2013-01-31T09:20:48.103 回答
2
while(fgets(line ,STRSIZE∗NFIELDS, fp))
                         ^
                         ^

Should be

while(fgets(line ,STRSIZE*NFIELDS, fp))
                         ^
                         ^

(Whether you see a difference between the two depends on the font used to display the characters).

The ∗ in the first one is not the character used for the multiplication operator, it is this character here.

于 2013-01-31T09:21:57.613 回答
0

Your "*" character in STRSIZE*NFIELDS is not the regular * (ascii value 42) but an unicode character "ASTERISK OPERATOR" : http://www.fileformat.info/info/unicode/char/2217/index.htm

That's what the compiler is trying to tell you by complaining about stray characters in the source.

于 2013-01-31T09:23:24.650 回答