Syntax errors on a few lines of almost complete code in C

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 3131 Views - Last Post: 10 April 2012 - 01:14 PM Rate Topic: -----

#1 kevinmc86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-April 12

Syntax errors on a few lines of almost complete code in C

Posted 05 April 2012 - 07:59 PM

The following is the code that I have created so far. However, I am getting syntax errors. Please give me a hint on where to look. I have posted the error log below the code.

[
// Description:
// This program creates an array with entires from
//  1 to 100 and randomizes them in different ways.

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

void printArray (int inputArr [100], int size);
void randomizeArray (int inputArr [100], int size);
void bubbleSortArray (int inputArr [100], int size);
void swap(int value, int currPos);


void main(void)
{//open braces for main function
   int inputArr [100];                    // integer type array of size 100.
   int index = 0;                         // integer type index starting from point zero.
   int size = 100;                        // declaring the size of the array to be 100.
   for (index; index < 100; index++)
   {
      inputArr [index] = index + 1;
   }
   printArray (inputArr, size);     
	randomizeArray (inputArr, size);
	printArray (inputArr, size);
	bubbleSortArray (inputArr, size);
	printArray (inputArr, size);
   system("PAUSE");
}//end of main.


/*
Function:   printArray (int inputArr[], int size)
Descr:      This function will print the array contents, 10 numbers per line. 
            Each number should be right justified in a field of size 5. 
Input:      inputArray[] (The integer type Array)
            size (The size of the array, which is 100)
Return:     This is a void function or non return type function. 
*/
{
void printArray (int inputArr[100], int size);
                                          //open braces for printarray function.                          
   int index;                               // declaring index for the for loop.     
   for (index = 0; index < 100; index++)
                                           //open braces for for loop.
      printf("%5d", inputArr[index]);
      if(index % 10 == 9 );
         printf("\n");
                                          //closing braces for main fucntion.
}                                           //end of printArray function.

/*
Function:   randomizeArray (int inputArr[], int size)
Descr:      This function will randomize the array according to the algorithm.
Input:      inputArray[] (The integer type Array)
            size (The size of the array, which is 100)
Return:     This is a void function or non return type function. 
*/

void randomizeArray ( int inputArr[], int size)
//open braces for randomizearray function.
   int currPos;                           // declaring int type currentposition for the for loop
   int randomIndex;                       // randomIndex as an int type variable. 
   unsigned seed = 10;
   int value;
   srand(seed);
   for (currPos = 0; currPos < size; currPos++)
   {
      randomIndex = rand() % size;
      swap(&inputArr[randomIndex], &inputArr[currPos]);
   }
}//closing braces for randomizearray function.
/*
Function:   bubbleSortArray(int inputArr[], int size)
Descr:      This function will sort the elements in the array. 
Input:      inputArray[] (The integer type Array)
            size (The size of the array, which is 100)
Return:     This is a void function or non return type function. 
*/


void bubbleSortArray(int inputArr[], int size)
{//open braces for bubblesort function.
   int i;                              // outer index for for loop.
   int j;                              // inner ondex for for loop.

   for (i = 99; i > 0; i--)
   {//open braces for for loop.

      for(j=0; j<=i-1; j++)
      {//open braces for inner for loop.
          if (inputArr[j]>inputArr[j+1])
          {
                swap(&inputArr[j], &inputArr[j+1]);  
          }
      }//closing braces for inner for loop.
   }//closing braces for outer for loop.
}//closing braces for bubblesortarray.


 
/*
Function:   swap(int* value, int* currPos)
Descr:      This function will swap two integers by the help of pointers.
Input:      *value (pointer to an integer)
            *currpos (Pointer to an integer)
            size (The size of the array, which is 100)
Return:     This is a void function or non return type function. 
*/

void swap(int* value, int* currPos)
{//open braces for swap fucntion.
   int temp=*currPos;
   *currPos=*value;
   *value=temp;
}//closing braces for swap function.


]

Errors in the output
[ERROR: argument 2 of the function is undefined or not a valid expression
ERROR: syntax error before or at line 51 in file '\\vmware-host\Shared Folders\VMware Shared Folder\array.c'
==>: printf("%5d", inputArr[index]);
BUG: printf("%5d", inputArr<== ???
ERROR: variable 'inputArr' not defined
ERROR: syntax error before or at line 51 in file '\\vmware-host\Shared Folders\VMware Shared Folder\array.c'
==>: printf("%5d", inputArr[index]);
BUG: printf("%5d", inputArr<== ???
ERROR: missing ';' before ']'
ERROR: syntax error before or at line 51 in file '\\vmware-host\Shared Folders\VMware Shared Folder\array.c'
==>: printf("%5d", inputArr[index]);
BUG: printf("%5d", inputArr[index]<== ???
ERROR: upper limit for array extent of dimension 1 in arg 1 is changed
ERROR: syntax error before or at line 67 in file '\\vmware-host\Shared Folders\VMware Shared Folder\array.c'
==>: int currPos; // declaring int type currentposition for the for loop
BUG: int<== ???
ERROR: invalid operands for less than operator <
ERROR: missing ';' in for-loop
ERROR: syntax error before or at line 72 in file '\\vmware-host\Shared Folders\VMware Shared Folder\array.c'
==>: for (currPos = 0; currPos < size; currPos++)
BUG: for (currPos = 0; currPos < size;<== ???
ERROR: missing ';' before ')'
ERROR: syntax error before or at line 72 in file '\\vmware-host\Shared Folders\VMware Shared Folder\array.c'
==>: for (currPos = 0; currPos < size; currPos++)
BUG: for (currPos = 0; currPos < size; currPos++)<== ???
ERROR: invalid lvalue of assignment operation
ERROR: syntax error before or at line 74 in file '\\vmware-host\Shared Folders\VMware Shared Folder\array.c'
==>: randomIndex = rand() % size;
BUG: randomIndex = rand() % size<== ???
ERROR: operand of address operation & is not a valid lvalue
ERROR: argument 1 of the function is undefined or not a valid expression
ERROR: number of argument is 1, need 2 arguERROR: argument 2 of the function is undefined or not a valid expression
ERROR: syntax error before or at line 51 in file 'array.c'
==>: printf("%5d", inputArr[index]);
BUG: printf("%5d", inputArr<== ???
ERROR: variable 'inputArr' not defined
ERROR: syntax error before or at line 51 in file 'array.c'
==>: printf("%5d", inputArr[index]);
BUG: printf("%5d", inputArr<== ???
ERROR: missing ';' before ']'
ERROR: syntax error before or at line 51 in file 'array.c'
==>: printf("%5d", inputArr[index]);
BUG: printf("%5d", inputArr[index]<== ???
ERROR: upper limit for array extent of dimension 1 in arg 1 is changed
ERROR: syntax error before or at line 67 in file 'array.c'
==>: int currPos; // declaring int type currentposition for the for loop
BUG: int<== ???
ERROR: invalid operands for less than operator <
ERROR: missing ';' in for-loop
ERROR: syntax error before or at line 72 in file 'array.c'
==>: for (currPos = 0; currPos < size; currPos++)
BUG: for (currPos = 0; currPos < size;<== ???
ERROR: missing ';' before ')'
ERROR: syntax error before or at line 72 in file 'array.c'
==>: for (currPos = 0; currPos < size; currPos++)
BUG: for (currPos = 0; currPos < size; currPos++)<== ???
ERROR: invalid lvalue of assignment operation
ERROR: syntax error before or at line 74 in file 'array.c'
==>: randomIndex = rand() % size;
BUG: randomIndex = rand() % size<== ???
ERROR: operand of address operation & is not a valid lvalue
ERROR: argument 1 of the function is undefined or not a valid expression
ERROR: number of argument is 1, need 2 arguments
ERROR: syntax error before or at line 75 in file 'array.c'
==>: swap(&inputArr[randomIndex], &inputArr[currPos]);
BUG: swap(&inputArr[<== ???
ERROR: missing ';' before ']'
ERROR: syntax error before or at line 75 in file 'array.c'
==>: swap(&inputArr[randomIndex], &inputArr[currPos]);
BUG: swap(&inputArr[randomIndex]<== ???
ERROR: operand of address operation & is not a valid lvalue
ERROR: syntax error before or at line 75 in file 'array.c'
==>: swap(&inputArr[randomIndex], &inputArr[currPos]);
BUG: swap(&inputArr[randomIndex], &inputArr<== ???
ERROR: maybe missing '}' at the end of program at line 75 or there is an extra '{' in other place in file 'array.c'
ERROR: cannot execute command 'array.c'
]

Thanks in advance!!!



:code:

This post has been edited by jimblumberg: 05 April 2012 - 08:03 PM
Reason for edit:: Added missing Code Tags, Please learn to use them.


Is This A Good Question/Topic? 0
  • +

Replies To: Syntax errors on a few lines of almost complete code in C

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4002
  • View blog
  • Posts: 12,347
  • Joined: 25-December 09

Re: Syntax errors on a few lines of almost complete code in C

Posted 05 April 2012 - 08:13 PM

You need to read the function tutorials provided in my signature below. You have missing braces on most of your functions.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 kevinmc86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-April 12

Re: Syntax errors on a few lines of almost complete code in C

Posted 06 April 2012 - 06:04 AM

View Postjimblumberg, on 05 April 2012 - 08:13 PM, said:

You need to read the function tutorials provided in my signature below. You have missing braces on most of your functions.

Jim


I am showing my comments for all the braces open and cloing. Could you point out a particular line example?
Thanks
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 4002
  • View blog
  • Posts: 12,347
  • Joined: 25-December 09

Re: Syntax errors on a few lines of almost complete code in C

Posted 06 April 2012 - 06:35 AM

You need to learn to decipher your error messages:

Quote

[ERROR: argument 2 of the function is undefined or not a valid expression
ERROR: syntax error before or at line 51 in file '\\vmware-host\Shared Folders\VMware Shared Folder\array.c'

I highlighted some important elements of your first error message. It is talking about an argument on or before line 51. Line 51 should be the last line of the following snippet:
{
void printArray (int inputArr[100], int size);
                                          //open braces for printarray function.                          
   int index;                               // declaring index for the for loop.     
   for (index = 0; index < 100; index++)
                                           //open braces for for loop.
      printf("%5d", inputArr[index]);
      if(index % 10 == 9 );
         printf("\n");
                                          //closing braces for main fucntion.
}                                           //end of printArray function.


There appears to be nothing wrong with that line so start looking a the lines prior to the stated line. So start by finding the beginning brace to match the closing brace. Can you find it? Where does it belong? Also look for stray semicolons where they don't belong, and maybe other missing braces. You have all kinds of comments but do these comments actually match your source? In this small snippet you have at least 4 problems. One misplaced starting brace, one control statement missing both opening and closing braces, and two semicolons where they don't belong.

I would say that you are probably not compiling often enough because of the amount of errors you are receiving. You should compile much more often. By compiling more often you will know where to start looking for your problems. I normally compile after only a few lines. Most times when I create a function I start with the function header and immediately put on both the open and close braces along with supplying some return value if required.
int myFunction(int someValue)
{

   return 0;
}


I then fill in the "blanks", and change the return value to return the correct value. By starting with this type of framework my program should compile without errors at this point and if not I have a very good place to start to find any errors. The more you compile your program the fewer errors you should have and therefore making it easier to locate the errors.



Jim

This post has been edited by jimblumberg: 06 April 2012 - 06:36 AM

Was This Post Helpful? 1
  • +
  • -

#5 kevinmc86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-April 12

Re: Syntax errors on a few lines of almost complete code in C

Posted 10 April 2012 - 06:47 AM

[
// Description:
// This program creates an array with entires from
//  1 to 100 and randomizes them in different ways.

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

void printArray (int inputArr [100], int size);
void randomizeArray (int inputArr [100], int size);
void bubbleSortArray (int inputArr [100], int size);
void swap(int value, int currPos);


int main(void)
{                                         // open braces for main function
   int inputArr [100];                    // integer type array of size 100.
   int index = 0;                         // integer type index starting from point zero.
   int size = 100;                        // declaring the size of the array to be 100.
   for (index; index < 100; index++)
   {
    inputArr [index] = index + 1;
    printArray (inputArr, size);     
	randomizeArray (inputArr, size);
	printArray (inputArr, size);
	bubbleSortArray (inputArr, size);
	printArray (inputArr, size);
    system("PAUSE");
    return 0;
}//end of main.


/*
Function:   printArray (int inputArr[], int size)
Descr:      This function will print the array contents, 10 numbers per line. 
            Each number should be right justified in a field of size 5. 
Input:      inputArray[] (The integer type Array)
            size (The size of the array, which is 100)
Return:     This is a void function or non return type function. 
*/

void printArray (int inputArr[100], int size);
  {                                         //open braces for printarray function.                          
   int index;                               // declaring index for the for loop.     
   for (index = 0; index < 100; index++)
   {                                        //open braces for for loop.
      printf("%5d", inputArr[index]);
      if(index % 10 == 9 );
         printf("\n");
    }                                       //closing braces for main fucntion.
}                                           //end of printArray function.

/*
Function:   randomizeArray (int inputArr[], int size)
Descr:      This function will randomize the array according to the algorithm.
Input:      inputArray[] (The integer type Array)
            size (The size of the array, which is 100)
Return:     This is a void function or non return type function. 
*/

void randomizeArray ( int inputArr[], int size)
{//open braces for randomizearray function.
   int currPos;                           // declaring int type currentposition for the for loop
   int randomIndex;                       // randomIndex as an int type variable. 
   unsigned seed = 10;
   int value;
   srand(seed);
   for (currPos = 0; currPos < size; currPos++)
   {
      randomIndex = rand() % size;
      swap(inputArr[randomIndex], inputArr[currPos]);
   }
}//closing braces for randomizearray function.

/*
Function:   bubbleSortArray(int inputArr[], int size)
Descr:      This function will sort the elements in the array. 
Input:      inputArray[] (The integer type Array)
            size (The size of the array, which is 100)
Return:     This is a void function or non return type function. 
*/


void bubbleSortArray(int inputArr[], int size)
{//open braces for bubblesort function.
   int i;                              // outer index for for loop.
   int j;                              // inner ondex for for loop.

   for (i = 99; i > 0; i--)
   {//open braces for for loop.

      for(j=0; j<=i-1; j++)
      {//open braces for inner for loop.
          if (inputArr[j]>inputArr[j+1])
          {
                swap(inputArr[j], inputArr[j+1]);  
          }
      }//closing braces for inner for loop.
   }//closing braces for outer for loop.
}//closing braces for bubblesortarray.


 
/*
Function:   swap(int* value, int* currPos)
Descr:      This function will swap two integers by the help of pointers.
Input:      *value (pointer to an integer)
            *currpos (Pointer to an integer)
            size (The size of the array, which is 100)
Return:     This is a void function or non return type function. 
*/

void swap(int* value, int* currPos)
{//open braces for swap fucntion.
   int temp=*currPos;
   *currPos=*value;
   *value=temp;
}//closing braces for swap function.
}

]

This is what I came up with after your suggestions. However it is outputting the following.

ERROR: function 'printArray()' not defined
ERROR: function 'randomizeArray()' not defined
ERROR: function 'bubbleSortArray()' not defined
ERROR: function 'swap()' not defined

I feel like it is a very simple thing that I am not getting but I have the functions defined in the beginning lines.

Thanks


:code:

This post has been edited by jimblumberg: 10 April 2012 - 06:52 AM
Reason for edit:: Fixed Code tags.

Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg  Icon User is offline

  • member icon


Reputation: 4002
  • View blog
  • Posts: 12,347
  • Joined: 25-December 09

Re: Syntax errors on a few lines of almost complete code in C

Posted 10 April 2012 - 06:56 AM

Your indentation needs work. With proper indentation you should be able to easily spot the problem (missing brace).

// Description:
// This program creates an array with entires from
//  1 to 100 and randomizes them in different ways.

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

void printArray (int inputArr [100], int size);
void randomizeArray (int inputArr [100], int size);
void bubbleSortArray (int inputArr [100], int size);
void swap(int value, int currPos);


int main(void)
{  // open braces for main function
   int inputArr [100];                    // integer type array of size 100.
   int index = 0;                         // integer type index starting from point zero.
   int size = 100;                        // declaring the size of the array to be 100.
   for (index; index < 100; index++)
   {
      inputArr [index] = index + 1;
      printArray (inputArr, size);
      randomizeArray (inputArr, size);
      printArray (inputArr, size);
      bubbleSortArray (inputArr, size);
      printArray (inputArr, size);
      system("PAUSE");
      return 0;
   }//end of main.


   /*
   Function:   printArray (int inputArr[], int size)
   Descr:      This function will print the array contents, 10 numbers per line.
               Each number should be right justified in a field of size 5.
   Input:      inputArray[] (The integer type Array)
               size (The size of the array, which is 100)
   Return:     This is a void function or non return type function.
   */

   void printArray (int inputArr[100], int size);
   {  //open braces for printarray function.
      int index;                               // declaring index for the for loop.
      for (index = 0; index < 100; index++)
      {  //open braces for for loop.
         printf("%5d", inputArr[index]);
         if(index % 10 == 9 );
         printf("\n");
      }                                       //closing braces for main fucntion.
   }                                           //end of printArray function.

   /*
   Function:   randomizeArray (int inputArr[], int size)
   Descr:      This function will randomize the array according to the algorithm.
   Input:      inputArray[] (The integer type Array)
               size (The size of the array, which is 100)
   Return:     This is a void function or non return type function.
   */

   void randomizeArray ( int inputArr[], int size)
   {  //open braces for randomizearray function.
      int currPos;                           // declaring int type currentposition for the for loop
      int randomIndex;                       // randomIndex as an int type variable.
      unsigned seed = 10;
      int value;
      srand(seed);
      for (currPos = 0; currPos < size; currPos++)
      {
         randomIndex = rand() % size;
         swap(inputArr[randomIndex], inputArr[currPos]);
      }
   }//closing braces for randomizearray function.

   /*
   Function:   bubbleSortArray(int inputArr[], int size)
   Descr:      This function will sort the elements in the array.
   Input:      inputArray[] (The integer type Array)
               size (The size of the array, which is 100)
   Return:     This is a void function or non return type function.
   */


   void bubbleSortArray(int inputArr[], int size)
   {  //open braces for bubblesort function.
      int i;                              // outer index for for loop.
      int j;                              // inner ondex for for loop.

      for (i = 99; i > 0; i--)
      {  //open braces for for loop.

         for(j=0; j<=i-1; j++)
         {  //open braces for inner for loop.
            if (inputArr[j]>inputArr[j+1])
            {
               swap(inputArr[j], inputArr[j+1]);
            }
         }//closing braces for inner for loop.
      }//closing braces for outer for loop.
   }//closing braces for bubblesortarray.



   /*
   Function:   swap(int* value, int* currPos)
   Descr:      This function will swap two integers by the help of pointers.
   Input:      *value (pointer to an integer)
               *currpos (Pointer to an integer)
               size (The size of the array, which is 100)
   Return:     This is a void function or non return type function.
   */

   void swap(int* value, int* currPos)
   {  //open braces for swap fucntion.
      int temp=*currPos;
      *currPos=*value;
      *value=temp;
   }//closing braces for swap function.
}
 


Then after you fix the braces look for semicolons where they don't belong.

Jim

This post has been edited by jimblumberg: 10 April 2012 - 06:57 AM

Was This Post Helpful? 0
  • +
  • -

#7 kevinmc86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-April 12

Re: Syntax errors on a few lines of almost complete code in C

Posted 10 April 2012 - 07:59 AM

View Postjimblumberg, on 10 April 2012 - 06:56 AM, said:

Your indentation needs work. With proper indentation you should be able to easily spot the problem (missing brace).

// Description:
// This program creates an array with entires from
//  1 to 100 and randomizes them in different ways.

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

void printArray (int inputArr [100], int size);
void randomizeArray (int inputArr [100], int size);
void bubbleSortArray (int inputArr [100], int size);
void swap(int value, int currPos);


int main(void)
{  // open braces for main function
   int inputArr [100];                    // integer type array of size 100.
   int index = 0;                         // integer type index starting from point zero.
   int size = 100;                        // declaring the size of the array to be 100.
   for (index; index < 100; index++)
   {
      inputArr [index] = index + 1;
      printArray (inputArr, size);
      randomizeArray (inputArr, size);
      printArray (inputArr, size);
      bubbleSortArray (inputArr, size);
      printArray (inputArr, size);
      system("PAUSE");
      return 0;
   }//end of main.


   /*
   Function:   printArray (int inputArr[], int size)
   Descr:      This function will print the array contents, 10 numbers per line.
               Each number should be right justified in a field of size 5.
   Input:      inputArray[] (The integer type Array)
               size (The size of the array, which is 100)
   Return:     This is a void function or non return type function.
   */

   void printArray (int inputArr[100], int size);
   {  //open braces for printarray function.
      int index;                               // declaring index for the for loop.
      for (index = 0; index < 100; index++)
      {  //open braces for for loop.
         printf("%5d", inputArr[index]);
         if(index % 10 == 9 );
         printf("\n");
      }                                       //closing braces for main fucntion.
   }                                           //end of printArray function.

   /*
   Function:   randomizeArray (int inputArr[], int size)
   Descr:      This function will randomize the array according to the algorithm.
   Input:      inputArray[] (The integer type Array)
               size (The size of the array, which is 100)
   Return:     This is a void function or non return type function.
   */

   void randomizeArray ( int inputArr[], int size)
   {  //open braces for randomizearray function.
      int currPos;                           // declaring int type currentposition for the for loop
      int randomIndex;                       // randomIndex as an int type variable.
      unsigned seed = 10;
      int value;
      srand(seed);
      for (currPos = 0; currPos < size; currPos++)
      {
         randomIndex = rand() % size;
         swap(inputArr[randomIndex], inputArr[currPos]);
      }
   }//closing braces for randomizearray function.

   /*
   Function:   bubbleSortArray(int inputArr[], int size)
   Descr:      This function will sort the elements in the array.
   Input:      inputArray[] (The integer type Array)
               size (The size of the array, which is 100)
   Return:     This is a void function or non return type function.
   */


   void bubbleSortArray(int inputArr[], int size)
   {  //open braces for bubblesort function.
      int i;                              // outer index for for loop.
      int j;                              // inner ondex for for loop.

      for (i = 99; i > 0; i--)
      {  //open braces for for loop.

         for(j=0; j<=i-1; j++)
         {  //open braces for inner for loop.
            if (inputArr[j]>inputArr[j+1])
            {
               swap(inputArr[j], inputArr[j+1]);
            }
         }//closing braces for inner for loop.
      }//closing braces for outer for loop.
   }//closing braces for bubblesortarray.



   /*
   Function:   swap(int* value, int* currPos)
   Descr:      This function will swap two integers by the help of pointers.
   Input:      *value (pointer to an integer)
               *currpos (Pointer to an integer)
               size (The size of the array, which is 100)
   Return:     This is a void function or non return type function.
   */

   void swap(int* value, int* currPos)
   {  //open braces for swap fucntion.
      int temp=*currPos;
      *currPos=*value;
      *value=temp;
   }//closing braces for swap function.
}
 


Then after you fix the braces look for semicolons where they don't belong.

Jim


I am sorry but is there any way you could be more specific? Maybe a hint?
Was This Post Helpful? 0
  • +
  • -

#8 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Syntax errors on a few lines of almost complete code in C

Posted 10 April 2012 - 09:01 AM

You have to remember that a semicolon terminates a statement.

An if structure has several parts:
if (expr)
statement;

An if structure should never have a semicolon immediately following the parentheses because then the "if" would have no effect whatsoever.

Your IDE should be warning you about things like this, but I noticed that in the long list of error messages that you posted, there is not a single warning message. I believe you're using Xcode, which means your compiler is in all likelihood GCC? I'm not familiar with Xcode, but you should look for -Wall -Wextra -pedantic checkboxes somplace in the project configuration options.
Was This Post Helpful? 0
  • +
  • -

#9 kevinmc86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-April 12

Re: Syntax errors on a few lines of almost complete code in C

Posted 10 April 2012 - 09:08 AM

View Postr.stiltskin, on 10 April 2012 - 09:01 AM, said:

You have to remember that a semicolon terminates a statement.

An if structure has several parts:
if (expr)
statement;

An if structure should never have a semicolon immediately following the parentheses because then the "if" would have no effect whatsoever.

Your IDE should be warning you about things like this, but I noticed that in the long list of error messages that you posted, there is not a single warning message. I believe you're using Xcode, which means your compiler is in all likelihood GCC? I'm not familiar with Xcode, but you should look for -Wall -Wextra -pedantic checkboxes somplace in the project configuration options.


I am using ChIDE
Was This Post Helpful? 0
  • +
  • -

#10 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Syntax errors on a few lines of almost complete code in C

Posted 10 April 2012 - 09:19 AM

Never heard of it before this moment. I don't know if it has any configuration options, but based on a quick look at their website I wouldn't be too hopeful.

Are you required to use that?
Was This Post Helpful? 0
  • +
  • -

#11 kevinmc86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-April 12

Re: Syntax errors on a few lines of almost complete code in C

Posted 10 April 2012 - 09:33 AM

View Postr.stiltskin, on 10 April 2012 - 09:19 AM, said:

Never heard of it before this moment. I don't know if it has any configuration options, but based on a quick look at their website I wouldn't be too hopeful.

Are you required to use that?


It is requested that I use it yes. It has seemed to work fine but this particular code is giving me problems. Are you saying that it wont ever run in this program or do I need to just correct what I have?

Thanks in advance
Was This Post Helpful? 0
  • +
  • -

#12 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Syntax errors on a few lines of almost complete code in C

Posted 10 April 2012 - 09:43 AM

You need to make the syntax correction regarding the if statement regardless of IDE.

I question the choice of IDE because I would never recommend such a non-mainstream environment for learning any programming language. My gut reaction is that someone did a really great job of selling that to some gullible school administrators. My preference would be one of the excellent free development environments that are used by "real" programmers to write "real" programs, such as CodeBlocks, Xcode, and Visual C++ Express. But that's just my opinion.
Was This Post Helpful? 0
  • +
  • -

#13 jimblumberg  Icon User is offline

  • member icon


Reputation: 4002
  • View blog
  • Posts: 12,347
  • Joined: 25-December 09

Re: Syntax errors on a few lines of almost complete code in C

Posted 10 April 2012 - 12:08 PM

Also look at the end of your function implementations, semicolons do not belong at the end of your implementation header:

void ThisIsAFunctionImplementation(void); // note the semicolon does not belong here.
{
}


Jim
Was This Post Helpful? 0
  • +
  • -

#14 kevinmc86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-April 12

Re: Syntax errors on a few lines of almost complete code in C

Posted 10 April 2012 - 12:29 PM

View Postjimblumberg, on 10 April 2012 - 12:08 PM, said:

Also look at the end of your function implementations, semicolons do not belong at the end of your implementation header:

void ThisIsAFunctionImplementation(void); // note the semicolon does not belong here.
{
}


Jim


I am at a lose, I cannot understand why it states that the function is not defined. Is it as simple as a bracket and that is it something more because I have looked through the code and cannot understand the error.
Was This Post Helpful? 0
  • +
  • -

#15 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Syntax errors on a few lines of almost complete code in C

Posted 10 April 2012 - 12:59 PM

Because a function definition consists of three parts:
the return type
the signature (name and argument list)
the body

If you put a semicolon at the end of the signature all you have is a prototype, which is a declaration, not a definition, of the function. And then the body (the code inside the braces) is just "lost code" that is not part of any function, and cannot run.

In order to have a valid function definition, you can't have a semicolon separating the signature from the body. It's that simple. There's really nothing to "understand"; you just have to follow the syntax rules of the language.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2