Thread: Weird Turbo C based, Graphics program error

  1. #1
    Registered User
    Join Date
    Nov 2012
    Location
    Bangalore, India, India
    Posts
    3

    Weird Turbo C based, Graphics program error

    Hello,


    The error that it displays is "Error: Expected )", at the 65th line. but that line (Insert function) does not have any such missing ')'

    I have tried a lot of things, but haven't managed to sort out this error. Please help!

    Code:
    1. #include <stdio.h>
    2. #include <stdlib.h>
    3. #include <ctype.h>
    4. #include <dos.h>
    5. #include <string.h>
    6. #include <graphics.h>
    7. struct node
    8. {
    9. int element;
    10. struct node *left;
    11. struct node *right;
    12. int height;
    13. };
    14. typedef struct node *nodeptr;
    15. /*void insert(int nodeptr&);
    16. void del(int nodeptr&);
    17. int deletemin(nodeptr &);
    18. void find(int nodeptr &);
    19. nodeptr findmin(nodeptr);
    20. nodeptr findmax(nodeptr);
    21. void makeempty(nodeptr &);
    22. nodeptr nodecopy(nodeptr &);
    23. void preorder(nodeptr);
    24. void inorder(nodeptr);
    25. void postorder(nodeptr);
    26. int bsheight(nodeptr);
    27. nodeptr singlerotateleft(nodeptr &);
    28. nodeptr doublerotateleft(nodeptr &);
    29. nodeptr singlerotateright(nodeptr &);
    30. nodeptr doublerotateright(nodeptr &);
    31. int max(int,int);
    32. int nonodes(nodeptr);
    33. */
    34. int gdriver=DETECT,gmode=0,errorcode;
    35. char element[3];
    36. int x=1,maxx,midx,xcoord,ycoord,level=320,prevlevel;
    37. void GDisplay(nodeptr p,int xcoord,int ycoord)
    38. {
    39. if (p!=NULL)
    40. {
    41. level=level/2;
    42. setfillstyle(1,BROWN);
    43. setcolor(LIGHTGREEN);
    44. if(p->left->element!=NULL)
    45. line(xcoord,ycoord,xcoord-level,ycoord+50);
    46. if(p->right->element!=NULL)
    47. line(xcoord,ycoord,xcoord+level,ycoord+50);
    48. fillellipse(xcoord,ycoord,10,10);
    49. sprintf(element,"%d",p->element,xcoord,ycoord);
    50. settextstyle(2,0,4);
    51. setcolor(YELLOW);
    52. outtextxy(xcoord-7,ycoord-7,element);
    53. GDisplay(p->left,xcoord-(level),ycoord+50);
    54. GDisplay(p->right,xcoord+(level),ycoord+50);
    55. level=level*2;
    56. }
    57. }//end of GDisplay
    58. void insert(int x,nodeptr& p)
    59. {
    60. if (p == NULL)
    61. {
    62. p = new node;
    63. p->element = x;
    64. p->left=NULL;
    65. p->right = NULL;
    66. p->height=0;
    67. if (p==NULL)
    68. {
    69. gotoxy(4,21);
    70. printf("Out of Space");
    71. }
    72. }
    73. else
    74. {
    75. if (x<p->element)
    76. {
    77. insert(x,p->left);
    78. //GDisplay(root,midx,50);
    79. if ((bsheight(p->left) - bsheight(p->right))==2)
    80. {
    81. if (x < p->left->element)
    82. p = singlerotateleft(p); //single rotation left
    83. else
    84. p = doublerotateleft(p); //double rotation left
    85. }
    86. }
    87. else if (x>p->element)
    88. {
    89. insert(x,p->right);
    90. //GDisplay(root,midx,50);
    91. if ((bsheight(p->right) - bsheight(p->left))==2)
    92. {
    93. if (x > p->right->element)
    94. p = singlerotateright(p); //single rotation right
    95. else
    96. p = doublerotateright(p); //double rotation right
    97. }
    98. }
    99. else
    100. {
    101. gotoxy(4,21);
    102. printf("Element Exists");
    103. }
    104. }
    105. int m,n,d;
    106. m=bsheight(p->left);
    107. n=bsheight(p->right);
    108. d=max(m,n);
    109. p->height = d + 1;
    110. }
    111. nodeptr findmin(nodeptr p)
    112. {
    113. if (p==NULL)
    114. {
    115. gotoxy(4,21); printf("Empty Tree");
    116. return p;
    117. }
    118. else
    119. {
    120. while(p->left !=NULL)
    121. p=p->left;
    122. return p;
    123. }
    124. }
    125. nodeptr findmax(nodeptr p)
    126. {
    127. if (p==NULL)
    128. {
    129. gotoxy(4,21); printf("Empty Tree");
    130. return p;
    131. }
    132. else
    133. {
    134. while(p->right !=NULL)
    135. p=p->right;
    136. return p;
    137. }
    138. }
    139. void find(int x,nodeptr &p)
    140. {
    141. if (p==NULL)
    142. {
    143. gotoxy(4,21);
    144. printf("Element not found");
    145. }
    146. else if (x < p->element)
    147. find(x,p->left);
    148. else if (x>p->element)
    149. find(x,p->right);
    150. else
    151. {
    152. gotoxy(4,21);
    153. printf("Element found !");
    154. }
    155. }
    156. void del(int x,nodeptr &p)
    157. {
    158. nodeptr d;
    159. if (p==NULL)
    160. {
    161. gotoxy(4,21);
    162. printf("Element not found");
    163. }
    164. else if ( x < p->element)
    165. {
    166. del(x,p->left);
    167. if ((bsheight(p->left) - bsheight(p->right))==2)
    168. {
    169. if (x < p->left->element)
    170. p = singlerotateleft(p); //single rotation left
    171. else
    172. p = doublerotateleft(p); //double rotation left
    173. }
    174. }
    175. else if (x > p->element)
    176. {
    177. del(x,p->right);
    178. if ((bsheight(p->right) - bsheight(p->left))==2)
    179. {
    180. if (x > p->right->element)
    181. p = singlerotateright(p); //single rotation right
    182. else
    183. p = doublerotateright(p); //double rotation right
    184. }
    185. }
    186. else if ((p->left == NULL) && (p->right == NULL))
    187. {
    188. d=p;
    189. free(d);
    190. p=NULL;
    191. gotoxy(4,21); printf("Element deleted !");
    192. }
    193. else if (p->left == NULL)
    194. {
    195. d=p;
    196. free(d);
    197. p=p->right;
    198. gotoxy(4,21); printf("Element deleted !");
    199. }
    200. else if (p->right == NULL)
    201. {
    202. d=p;
    203. p=p->left;
    204. free(d);
    205. gotoxy(4,21); printf("Element deleted !");
    206. }
    207. else
    208. p->element = deletemin(p->right);
    209. }
    210. int deletemin(nodeptr &p)
    211. {
    212. int c;
    213. gotoxy(4,21); printf("deltemin");
    214. if (p->left == NULL)
    215. {
    216. c=p->element;
    217. p=p->right;
    218. return c;
    219. }
    220. else
    221. {
    222. c=deletemin(p->left);
    223. return c;
    224. }
    225. }
    226. void preorder(nodeptr p)
    227. {
    228. if (p!=NULL)
    229. {
    230. printf("%d-->",p->element);
    231. preorder(p->left);
    232. preorder(p->right);
    233. }
    234. }
    235. void inorder(nodeptr p)
    236. {
    237. if (p!=NULL)
    238. {
    239. inorder(p->left);
    240. printf("%d-->",p->element);
    241. inorder(p->right);
    242. }
    243. }
    244. void postorder(nodeptr p)
    245. {
    246. if (p!=NULL)
    247. {
    248. postorder(p->left);
    249. postorder(p->right);
    250. printf("%d-->",p->element);
    251. }
    252. }
    253. int max(int value1, int value2)
    254. {
    255. if(value1 > value2)
    256. return value1;
    257. else
    258. return value2;
    259. }
    260. int bsheight(nodeptr p)
    261. {
    262. int t;
    263. if (p == NULL)
    264. return -1;
    265. else
    266. {
    267. t = p->height;
    268. return t;
    269. }
    270. }
    271. nodeptr singlerotateleft(nodeptr &p1)
    272. {
    273. nodeptr p2;
    274. p2 = p1->left;
    275. p1->left = p2->right;
    276. p2->right = p1;
    277. p1->height = max(bsheight(p1->left),bsheight(p1->right)) + 1;
    278. p2->height = max(bsheight(p2->left),p1->height) + 1;
    279. return p2;
    280. }
    281. nodeptr singlerotateright(nodeptr &p1)
    282. {
    283. nodeptr p2;
    284. p2 = p1->right;
    285. p1->right = p2->left;
    286. p2->left = p1;
    287. p1->height = max(bsheight(p1->left),bsheight(p1->right)) + 1;
    288. p2->height = max(p1->height,bsheight(p2->right)) + 1;
    289. return p2;
    290. }
    291. nodeptr doublerotateleft(nodeptr &p1)
    292. {
    293. p1->left = singlerotateright(p1->left);
    294. return singlerotateleft(p1);
    295. }
    296. nodeptr doublerotateright(nodeptr &p1)
    297. {
    298. p1->right = singlerotateleft(p1->right);
    299. return singlerotateright(p1);
    300. }
    301. //int count=0;
    302. int nonodes(nodeptr p)
    303. { int count=0;
    304. if (p!=NULL)
    305. {
    306. nonodes(p->left);
    307. nonodes(p->right);
    308. count++ ;
    309. }
    310. return count;
    311. }
    312. void twolinebox(int x1,int y1,int x2,int y2){
    313. int x,y;
    314. textcolor(WHITE);
    315. gotoxy(x1,y1); cprintf("É"); //201
    316. gotoxy(x2,y1); cprintf("»"); //187
    317. for(y=y1+1;y<y2;y++){
    318. gotoxy(x1,y); cprintf("º"); //186
    319. gotoxy(x2,y); cprintf("º"); //186
    320. }
    321. gotoxy(x1,y2); cprintf("È"); //200
    322. gotoxy(x2,y2); cprintf("¼"); //188
    323. for(x=x1+1;x<x2;x++){
    324. gotoxy(x,y1); cprintf("Í"); //205
    325. gotoxy(x,y2); cprintf("Í"); //205
    326. }
    327. gotoxy(x1+1,y1+1);
    328. }
    329. void cprintxy(int x,int y,int color,char string[]){
    330. textcolor(color);
    331. gotoxy(x,y); cprintf("%s",string);
    332. }
    333. void center(int y,int color,char string[]){
    334. int x=(80-strlen(string)+1)/2;
    335. textcolor(color);
    336. gotoxy(x,y);cprintf("%s",string);
    337. }
    338. void Temp(void){
    339. int x,y;
    340. clrscr();
    341. twolinebox(1,1,80,24);
    342. for(y=23;y>=1;y--){
    343. sound(60*y);
    344. center(y,YELLOW,"[Adelson-Velskii and Landis Tree]");
    345. gotoxy(2,y+1); clreol();
    346. twolinebox(1,1,80,24);
    347. delay(40);
    348. nosound();
    349. }
    350. center(1,YELLOW,"[Adelson-Velskii and Landis Tree]");
    351. for(x=74;x>=3;x--){
    352. sound(50*x);
    353. cprintxy(x,5,RED,"Press:");clreol();
    354. twolinebox(1,1,80,24);
    355. center(1,YELLOW,"[Adelson-Velskii and Landis Tree]");
    356. delay(20);
    357. nosound();
    358. }
    359. twolinebox(1,1,80,12);
    360. twolinebox(1,1,80,24);
    361. center(1,YELLOW,"[Adelson-Velskii and Landis Tree]");
    362. cprintxy(20,3,GREEN,"[A]- Insertion");
    363. cprintxy(20,4,GREEN,"- Find Minimum");
    364. cprintxy(20,5,GREEN,"[C]- Find Maximum");
    365. cprintxy(20,6,GREEN,"[D]- Search Node");
    366. cprintxy(20,7,GREEN,"[E]- Display Tree");
    367. cprintxy(43,3,GREEN,"[F]- Delete Node");
    368. cprintxy(43,4,GREEN,"[G]- Preorder");
    369. cprintxy(43,5,GREEN,"[H]- Inorder");
    370. cprintxy(43,6,GREEN,"- Postorder");
    371. cprintxy(43,7,GREEN,"[J]- Height");
    372. cprintxy(20,9,GREEN,"[any key]- Quit...");
    373. cprintxy(20,11,LIGHTRED,"Enter your choice: ");
    374. }
    375. void main()
    376. {
    377. nodeptr root,min,max;
    378. int a,findele,delele,leftele,rightele,flag;
    379. char choice,value[2];
    380. char ch='Y';
    381. root = NULL;
    382. textmode(80);
    383. Temp();
    384. do
    385. {
    386. clrscr();
    387. twolinebox(1,1,80,12);
    388. twolinebox(1,1,80,24);
    389. center(1,YELLOW,"[Adelson-Velskii and Landis Tree]");
    390. cprintxy(5,3,LIGHTRED,"Press: ");
    391. cprintxy(20,3,GREEN,"[A]- Insertion");
    392. cprintxy(20,4,GREEN,"- Find Minimum");
    393. cprintxy(20,5,GREEN,"[C]- Find Maximum");
    394. cprintxy(20,6,GREEN,"[D]- Search Node");
    395. cprintxy(20,7,GREEN,"[E]- Display Tree");
    396. cprintxy(43,3,GREEN,"[F]- Delete Node");
    397. cprintxy(43,4,GREEN,"[G]- Preorder");
    398. cprintxy(43,5,GREEN,"[H]- Inorder");
    399. cprintxy(43,6,GREEN,"- Postorder");
    400. cprintxy(43,7,GREEN,"[J]- Height");
    401. cprintxy(20,9,GREEN,"[any key]- Quit...");
    402. cprintxy(20,11,LIGHTRED,"Enter your choice:\>");
    403. choice=getch();
    404. switch(toupper(choice))
    405. {
    406. case 'A':
    407. do{
    408. gotoxy(4,14); printf("Enter node value: ");
    409. a=atoi(gets(value));
    410. if(atoi(value)==0)
    411. {
    412. gotoxy(4,21); printf("Error!!! Enter a valid integer value only.");
    413. gotoxy(4,22); printf("Press any key to continue...");
    414. getch();
    415. }
    416. }while(atoi(value)==0);
    417. insert(a,root);
    418. gotoxy(4,15);
    419. inorder(root);
    420. initgraph(&gdriver,&gmode,"c:\tc\bgi");
    421. errorcode = graphresult();
    422. maxx=getmaxx();
    423. midx=maxx/2,xcoord=midx/2,ycoord=40;
    424. if (errorcode != grOk)
    425. {
    426. printf("Graphics error: %d",grapherrormsg(errorcode));
    427. printf("Press any key to stop");
    428. getch();
    429. exit(1);
    430. }
    431. cleardevice();
    432. GDisplay(root,midx,50);
    433. getch();
    434. restorecrtmode();
    435. break;
    436. case 'B':
    437. if(root!=NULL)
    438. {
    439. min=findmin(root);
    440. gotoxy(4,14); printf("Min element : %d",min->element);
    441. }
    442. break;
    443. case 'C':
    444. if(root!=NULL)
    445. {
    446. max=findmax(root);
    447. gotoxy(4,14); printf("Max element : %d",max->element);
    448. }
    449. break;
    450. case 'D':
    451. gotoxy(4,14); printf("Search node :");
    452. scanf("%d",&findele);
    453. if(root!=NULL)
    454. find(findele,root);
    455. break;
    456. case 'E':
    457. initgraph(&gdriver,&gmode,"c:\tc\bgi");
    458. errorcode=graphresult();
    459. maxx=getmaxx();
    460. midx=maxx/2;
    461. xcoord=midx/2;
    462. ycoord=40;
    463. if(errorcode!=grOk)
    464. {
    465. printf("Graphics error: %d", grapherrormsg(errorcode));
    466. printf("Press any key to stop");
    467. getch();
    468. exit(1);
    469. }
    470. cleardevice();
    471. setbkcolor(LIGHTBLUE);
    472. settextstyle(2,0,5);
    473. outtextxy(20,10,"Adelson-Velskii and Landis Tree");
    474. GDisplay(root,midx,50);
    475. outtextxy(20,440,"Programmed by: Frederick Badion");
    476. outtextxy(20,450,"Polytechnic University of the Philippines");
    477. outtextxy(20,460,"2nd year Bachelor of Science in Computer Science");
    478. outtextxy(320,440,"A partial fulfilment for the subject: ");
    479. outtextxy(320,450,"Design and Analysis of Algorithm");
    480. outtextxy(320,460,"Prof. Ria Sagum -Chairperson BSCS-CCMITPUP-Sta.Mesa");
    481. getch();
    482. restorecrtmode();
    483. break;
    484. case 'F':
    485. gotoxy(4,14);printf("Delete node: ");
    486. scanf("%d",&delele);
    487. del(delele,root);
    488. getch();
    489. initgraph(&gdriver,&gmode,"c:tc\bgi");
    490. errorcode=graphresult();
    491. maxx=getmaxx();
    492. midx=maxx/2,xcoord=midx/2,ycoord=40;
    493. if(errorcode !=grOk)
    494. {
    495. printf("graphics error: %d",grapherror(errorcode));
    496. printf("Press any key to stop");
    497. getch();
    498. exit(1);
    499. }
    500. cleardevice();
    501. setbkcolor(LIGHTBLUE);
    502. settextstyle(2,0,5);
    503. outtexty(20,10,"Adelson-velskii and Landis tree");
    504. GDisplay(root,midx,50);
    505. getch();
    506. restorecrtmode();
    507. break;
    508. case 'G':
    509. gotoxy(4,14);printf("preorder printing.....");
    510. gotoxy(4,15);
    511. preorder(root);
    512. break;
    513. case 'H':
    514. gotoxy(4,14);printf("inorder printing....");
    515. gotoxy(4,15);
    516. inorder(root);
    517. break;
    518. case 'I':
    519. gotoxy(4,14);printf("postorder printing....");
    520. gotoxy(4,15);
    521. postorder(root);
    522. break;
    523. case 'J':
    524. gotoxy(4,14);printf("height and depth:%d",bsheight(root));
    525. gotoxy(4,15);printf("no of nodes:%d",nonodes(root));
    526. break;
    527. }
    528. gotoxy(4,22);printf("do you want to continue(y/n)?");
    529. ch=toupper(getch());
    530. }
    531. while (ch!='N');
    532. }
    Attached Files Attached Files

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Duplicate post from C++ programming.
    Probably the one at C++ programming will be deleted.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I have tried a lot of things, but haven't managed to sort out this error. Please help!
    Did you try compiling it before it got to 500+ lines long?

    Of course not, you're just another dumb-assed copy/paste programmer who found some piece of crap code on the web.
    AVL Tree with Graphics Display - Data Structures Source Code in C
    I can see why you have problems with the code formatting, the web-page is too ugly to feed to a dog.

    Having discovered (shock, horror) that it doesn't actually work, you roll up here and expect some other schmoe to do the work for you.

    It helps if you can recognise that this supposed C code is actually C++ code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    that is some ugly code, offends ones sensibilities - code can be a thing of beauty in my opinion, in the way it flows and looks on the screen - this is not an example of such a thing. yuk.

    And for crying out loud - india is one of the fastest growing economies - so we are constantly being told - The land is a vibrant pot of culture, invention, enterprise and ambition - so why the **** cant the progammers and tutors there get into the 21st ****ing century with the tools ?????????
    Last edited by rogster001; 11-18-2012 at 01:14 PM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  5. #5
    Registered User
    Join Date
    Nov 2012
    Location
    Bangalore, India, India
    Posts
    3
    @salem,
    Of course not, you're just another dumb-assed copy/paste programmer who found some piece of crap code on the web.
    yes, thats very true, I did find it online, but to learn, not to use in anything of my own. Yes, to you, that may seem to be "copy/paste" programming, but the truth of the matter is, that not everyone was born with C/cpp in their heads. Forgive me, but I came here to learn what was wrong with it. Not to use some other person's work. If you have nothing better to do than to creep around a forum where people come to learn, then you might as well have pointed me to the right direction, rather than pointing out the obvious.

    lastly, if you have nothing constructive to say, kindly don't say anything at all.


    by the way, I did sort the error out. As you said, it is a CPP code. Thats why I posted it in the CPP forum in the first place. I am not good with TurboC, and am being forced to run it in that(xp, virtualbox), as I use Linux, not windows.

    Pardon my words, if harsh,
    Thanks for the help, everyone, here, and in the cpp post....

  6. #6
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    you dont have to be born with c/c++ and it is ok to use a bit of copy paste here and there - once you know what you are doing - lifting 500 lines of code is certainly not going to help you - you need to learn a bit at a time - testing the various functions and features your program requires in small experimental parts. You definitely cannot learn at an early stage by trying to make a large amount of somebody else's code 'work'
    Last edited by rogster001; 11-18-2012 at 01:47 PM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    I am not good with TurboC, and am being forced to run it in that(xp, virtualbox), as I use Linux, not windows.
    And why are you being "forced to run it in that"? Could it be because your ass-backwards school, for which you're copying and pasting your assignment, requires it?

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > And for crying out loud - india is one of the fastest growing economies - so we are constantly being told
    You should read my sig-link, if you're still under that delusion.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    My guess is the problem is on line 58. That functions prototype was /* */ commented out on line 15. Try moving the /* down to line 16.

    Without a prototype, Turbo C/C++ assumed int, and since there is no int, and the parameter is not an int, it believes a closing parenthesis is needed - typically a few lines late for a larger program.

    Good luck. Would be a perfect time to re-write that program with good indentation, with a modern IDE and compiler.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. TurboC based, Graphics based program with weird error!
    By sidx64 in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2012, 12:48 PM
  2. Graphics problem in turbo c++
    By mushahidh in forum Game Programming
    Replies: 1
    Last Post: 10-31-2010, 08:22 AM
  3. Turbo C++ Graphics
    By Nomad Seifer in forum C++ Programming
    Replies: 1
    Last Post: 06-11-2002, 03:56 AM
  4. Turbo C++ vs Visual C++ , weird!!
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 08:34 AM
  5. graphics.h under Turbo C
    By newbie17 in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 11-22-2001, 05:17 AM