0

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;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tyler
  • 1,050
  • 2
  • 14
  • 24
  • 7
    You have a ∗ where you should have a * – dreamlax Jan 31 '13 at 09:19
  • Simply copy&paste the source from your question, this will fix it – Andreas Fester Jan 31 '13 at 09:20
  • @BillyONeal I did it, and it compiled (But, you are right, it depends on the editor where you paste it - SO still has the UNICODE character ...) – Andreas Fester Jan 31 '13 at 09:22
  • The order in the compiler errors is expected to be *"stray \342 ... \210 \227"*: 342 210 227 (octal) → 0xE2 0x88 0x97 (hexadecimal) → UTF-8 sequence for Unicode code point U+2217 ([ASTERISK OPERATOR](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8704&number=128)). It can be searched (and replaced) by regular expression `\x{2217}` (or `\u2217`) in any modern text editor, e.g. [Geany](https://pmortensen.eu/world2/2020/03/29/using-geany/) or [Visual Studio Code](https://en.wikipedia.org/wiki/Visual_Studio_Code). – Peter Mortensen Apr 27 '23 at 15:19
  • 1
    This is a ***very*** common error when copying code from web pages, [PDF](https://en.wikipedia.org/wiki/Portable_Document_Format) documents, through chat (e.g. [Skype Chat](https://en.wikipedia.org/wiki/Features_of_Skype#Skype_chat) or [Facebook Messenger](https://en.wikipedia.org/wiki/Facebook_Messenger)), etc. The canonical question is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen Apr 27 '23 at 15:23

3 Answers3

4

Your is not the mulitplication operator * , they may look similar, but are different characters, and gcc doesn't recognize the ∗

nos
  • 223,662
  • 58
  • 417
  • 506
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.

dreamlax
  • 93,976
  • 29
  • 161
  • 209
0

Your "" character in STRSIZENFIELDS is not the regular * (ASCII value 42), but a Unicode character "ASTERISK OPERATOR".

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Remi Gacogne
  • 4,655
  • 1
  • 18
  • 22