0

I'm writing a program in C that calls functions from the command line and it is coming up with errors all in the first line of code (the for statement) and I'm not sure why or what they are. It says "syntax error found, expecting ;" "syntax error found, expecting )" "undeclared indentifier i" and "illegal statement termination."

int main(int argc, char *argv[])
{
  for(int i = 0; i < argc; i++ )
  {
    if(0 == stricmp("ParameterA", argv[i]))
    {
      exec1 = TRUE;
    }
    else if(0 == stricmp("ParameterB", argv[i]))
    {
      exec2 = FALSE;
    }
    else if(0 == stricmp("ParameterC", argv[i]))
    {
      exec2 = TRUE;
    }
    else
    {
      fprintf(stderr, "Unknown parameter: %s", argv[i]);
    }
  }
}
Son-Huy Pham
  • 1,899
  • 18
  • 19

2 Answers2

1

In C variable should be declared before any executable code.

you can change the code to

int main(int argc, char *argv[])
{
    int i = 0;
    for(i = 0; i < argc; i++ )
    ...
Mayur Navadia
  • 241
  • 1
  • 4
0

In C you can't declare int i inside a FOR loop
declare int i before the loop

VitaliyG
  • 1,837
  • 1
  • 11
  • 11
  • 2
    In C99 it is possible to have the declaration of the int inside the for loop, e.g. `for (int i = 0;...` http://stackoverflow.com/questions/1287863/c-for-loop-int-initial-declaration But C99 is probably not what is being used by the OP. – Macattack Jul 02 '13 at 18:34