When trying to compile this short C program using GCC, I get these errors:
expected ‘)’ before numeric constant
make: *** [file3_5.o] Error 1
stray ‘\210’ in program
stray ‘\227’ in program
stray ‘\342’ in program
Eclipse 4.2 (Juno) points all of these errors to one line of code:
while(fgets(line ,STRSIZE∗NFIELDS, fp))
Using the following statement to compile:
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"
Here is the program I am trying to compile:
#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 the 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;
}