Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,424 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,952 people online right now. Registration is fast and FREE... Join Now!




C - Compile Error : ") Expected"

 
Reply to this topicStart new topic

C - Compile Error : ") Expected"

ISAI
12 Jan, 2008 - 09:44 AM
Post #1

New D.I.C Head
*

Joined: 26 Dec, 2007
Posts: 41


My Contributions
hello all.
i have a compiling error in c (i'm using "Borland C++" btw) which i cannot solve on my own.
it says ") Expected".. and i dont understand what is wrong with my code..
the error is in line 160, near the end of the code :

void addInsertSort(list **ptr,record data)

thanks a lot in advance.
here is my code :

CODE
#include <graphics.h>
#include <string.h>
#include <alloc.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include "d:\1vs100\button.h"
#include "d:\1vs100\mouse.h"
#include "d:\1vs100\high.h"
#include "d:\1vs100\menu.h"
#include "d:\1vs100\screens.h"

typedef struct
{
char name[25];
int nikud;
}rec;
typedef struct list
{
rec record;
struct list *next;
}list;
list *head=NULL;

void high()
{
  int c,d,i,status,places=2;
  button *array;

     array=(button*)malloc(places*sizeof(button)); // array of button
     if (array==NULL) // if memory=not enough room > NULL
    {
       printf("Not enough memory to allocate buffer!\n");
       getch();
       exit(0);
    }
     array[0]=InitButton(20,20,100,40,0,13,"Main Menu");
     array[1]=InitButton(20,45,100,65,0,13,"Quit");

     setcolor(9); // light blue
     settextstyle(4,0,4); // f,d,s
     outtextxy(210,50,"High Scores");
     setfillstyle(8,9); // s,c
     bar(15,480,0,0); // left frame
     bar(0,15,640,0); // up frame
     bar(623,480,640,0); // right frame
     bar(0,480,640,465); // down frame

     for(i=0;i<places;i++) DrawButton(array[i]);
     mouse_cursor_on();
     while(1)
    {
       for (i=0;i<places;i++)
          {
         read_mouse(&c,&d,&status);
         if ((c>=array[i].x1)&&(c<=array[i].x2)&&(d>=array[i].y1)&&(d<=array[i].y2)&&(status&0x01))
            {
               sound(250);
               delay(50);
               nosound();
               if (BPos(array[i])==0) // if not pressed
              {
                 array[i].pos=1;
                 DrawButton(array[i]);
                 delay(200); // illusion of button being pressed
                 array[i].pos=0;
                 DrawButton(array[i]);
                 if (i==0) // Main Menu
                {
                   mouse_cursor_off();
                   clearviewport();
                   menu();
                }

                 if (i==1) // Exit Game
                {
                   closegraph();
                   free(array);
                   sound(250);
                   delay(4);
                   nosound();
                   exit(1);
                }

              } // if

               if (BPos(array[i])==1)
              {
                 array[i].pos=0;
                 DrawButton(array[i]);
                 if (i==2)
                {
                   closegraph();
                   free(array);
                   sound(250);
                   delay(4);
                   nosound();
                   exit(1);
                } // if

                break;
              } // if
            } // if
          } // for
    } // while
} // high func

void addItem(list **headPtr,rec data)
{
list *ptr;
ptr=(list *)malloc(1*sizeof(list));
if (ptr)
  {
    if (*headPtr==NULL)
    {
        ptr->record=data;
        ptr->next=NULL;
        *headPtr=ptr;
    }
    else
    {
        list *temp=*headPtr;
        while(temp->next)
            temp=temp->next;
        ptr->record=data;
        ptr->next=NULL;
        temp->next=ptr;
    }
  } // if ptr
} // addItem func

void printList(list *headPtr)
{
rec data;
list *temp=headPtr;
while(temp)
  {
    data=temp->record;
    printf("%s%d",data.name,data.nikud);
    temp=temp->next;
  } // while
} // printList func

void insertSort(list **headPtr,rec data)
{
list *temp,*ptr;
temp=*headPtr;
while((temp)&&(temp->record.nikud>data.nikud))
  {
    ptr=temp;
    temp=temp->next;
  }
if(ptr==*headPtr)
    addInsertSort(); // was (headPtr,data)
else
    addInsertSort(); // was (&(ptr->next),data)
} // InsertSort func

void addInsertSort(list **ptr,record data)
{
list *temp=(list *)malloc(sizeOf(list));
if(temp)
  {
    temp->record=data;
    temp->next=*ptr;
    *ptr=temp;
  }
} // addInsertSort func

void main()
{
rec data;
strcpy(data.name,"hhjjj");
data.nikud=60;
addItem(&headPtr,data); // was "head", changed to "headPtr"
printList(headPtr); // was "head", changed to "headPtr"
} // main func


This post has been edited by ISAI: 12 Jan, 2008 - 09:46 AM
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: C - Compile Error : ") Expected"
12 Jan, 2008 - 10:53 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,260



Thanked: 227 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
I noticed that you are calling addInsertSort without parameters when the function requires two.

CODE

if(ptr==*headPtr)
    addInsertSort(); <-- Can't call without parameters
else
    addInsertSort(); <-- Can't call without parameters
} // InsertSort func



Second thing I noticed was that all your other functions use the second parameter of type "rec" and not "record" like you are doing for addInsertSort. Is this what you were intending was to use "rec data" instead of "record data"?

smile.gif
User is offlineProfile CardPM
+Quote Post

ISAI
RE: C - Compile Error : ") Expected"
13 Jan, 2008 - 02:34 AM
Post #3

New D.I.C Head
*

Joined: 26 Dec, 2007
Posts: 41


My Contributions
QUOTE(Martyr2 @ 12 Jan, 2008 - 11:53 AM) *

I noticed that you are calling addInsertSort without parameters when the function requires two.

CODE

if(ptr==*headPtr)
    addInsertSort(); <-- Can't call without parameters
else
    addInsertSort(); <-- Can't call without parameters
} // InsertSort func



Second thing I noticed was that all your other functions use the second parameter of type "rec" and not "record" like you are doing for addInsertSort. Is this what you were intending was to use "rec data" instead of "record data"?

smile.gif


I know the two functions should have parameters, but the borland c++ compiler showed me an error saying "extra parameter in call of addInsertSort();" twice. (one for the if and one for the else).
and when i deleted the parameters and left it (); the compiling error did not appear. so i thought that was the problem..
why doesn't it let me put parameters into the function if it's what i should do?

and about the second thing, yes that was my intention.

thanks for the reply btw=]

User is offlineProfile CardPM
+Quote Post

ISAI
RE: C - Compile Error : ") Expected"
15 Jan, 2008 - 02:05 AM
Post #4

New D.I.C Head
*

Joined: 26 Dec, 2007
Posts: 41


My Contributions
I fixed the compiling errors, by myself.. smile.gif
but now.. even tho after i did "Build All" => SUCCESS,
it doesn't show me the output of the High Score page.
how could that be?
here is the updated code:

CODE
#include <graphics.h>
#include <string.h>
#include <alloc.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include "d:\1vs100\button.h"
#include "d:\1vs100\mouse.h"
#include "d:\1vs100\high.h"
#include "d:\1vs100\menu.h"
#include "d:\1vs100\screens.h"

typedef struct
{
char name[25];
int nikud;
}rec;
typedef struct list
{
rec record;
struct list *next;
}list;
list *head=NULL;

void high()
{
  int c,d,i,status,places=2;
  button *array;

     array=(button*)malloc(places*sizeof(button)); // array of button
     if (array==NULL) // if memory=not enough room > NULL
    {
       printf("Not enough memory to allocate buffer!\n");
       getch();
       exit(0);
    }
     array[0]=InitButton(20,20,100,40,0,13,"Main Menu");
     array[1]=InitButton(20,45,100,65,0,13,"Quit");

     setcolor(9); // light blue
     settextstyle(4,0,4); // f,d,s
     outtextxy(210,50,"High Scores");
     setfillstyle(8,9); // s,c
     bar(15,480,0,0); // left frame
     bar(0,15,640,0); // up frame
     bar(623,480,640,0); // right frame
     bar(0,480,640,465); // down frame

     for(i=0;i<places;i++) DrawButton(array[i]);
     mouse_cursor_on();
     while(1)
    {
       for (i=0;i<places;i++)
          {
         read_mouse(&c,&d,&status);
         if ((c>=array[i].x1)&&(c<=array[i].x2)&&(d>=array[i].y1)&&(d<=array[i].y2)&&(status&0x01))
            {
               sound(250);
               delay(50);
               nosound();
               if (BPos(array[i])==0) // if not pressed
              {
                 array[i].pos=1;
                 DrawButton(array[i]);
                 delay(200); // illusion of button being pressed
                 array[i].pos=0;
                 DrawButton(array[i]);
                 if (i==0) // Main Menu
                {
                   mouse_cursor_off();
                   clearviewport();
                   menu();
                }

                 if (i==1) // Exit Game
                {
                   closegraph();
                   free(array);
                   sound(250);
                   delay(4);
                   nosound();
                   exit(1);
                }

              } // if

               if (BPos(array[i])==1)
              {
                 array[i].pos=0;
                 DrawButton(array[i]);
                 if (i==2)
                {
                   closegraph();
                   free(array);
                   sound(250);
                   delay(4);
                   nosound();
                   exit(1);
                } // if

                break;
              } // if
            } // if
          } // for
    } // while
} // high func

void addItem(list **headPtr,rec data)
{
list *ptr;
ptr=(list *)malloc(sizeof(list)); // 1*sizeof
if (ptr)
  {
    if (*headPtr==NULL)
    {
        ptr->record=data;
        ptr->next=NULL;
        *headPtr=ptr;
    }
    else
    {
        list *temp=*headPtr;
        while(temp->next)
            temp=temp->next;
        ptr->record=data;
        ptr->next=NULL;
        temp->next=ptr;
    }
  } // if ptr
} // addItem func

void printList(list *headPtr)
{
rec data;
list *temp=headPtr;
while(temp)
  {
    data=temp->record;
    printf("%s%d",data.name,data.nikud);
    temp=temp->next;
  } // while
} // printList func

void addInsertSort(list **ptr,rec data)
{
list *temp=(list *)malloc(sizeof(list));
if(temp)
  {
    temp->record=data;
    temp->next=*ptr;
    *ptr=temp;
  }
} // addInsertSort func

void insertSort(list **headPtr,rec data)
{
list *temp,*ptr;
temp=*headPtr;
while((temp)&&(temp->record.nikud>data.nikud))
  {
    ptr=temp;
    temp=temp->next;
  }
if(ptr==*headPtr)
    addInsertSort(headPtr,data);
else
    addInsertSort(&(ptr->next),data);
} // InsertSort func

void main1()
{
rec data;
strcpy(data.name,"whythehelldontiseethis");
data.nikud=60;
addItem(&head,data);
printList(head);
} // main1 func

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 04:37AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month