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!
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 :
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 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
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"?
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"?
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.
I fixed the compiling errors, by myself.. 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:
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