Advertisement
rmoronsv

Untitled

Dec 30th, 2019
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 198.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <float.h>
  3. #include <limits.h>
  4. #include <conio.h>
  5. #include <ctype.h>
  6. #include <string.h>
  7. #include <math.h>
  8.  
  9. //main()
  10. //{
  11. // printf("hello ");
  12. // printf("world");
  13. // printf("\n");
  14. // printf("\f");
  15. //
  16. //}
  17.  
  18. //main()
  19. //{
  20. // float fahr, celcius;
  21. // int lower, upper, step;
  22. //
  23. // lower = 0;
  24. // upper = 300;
  25. // step = 20;
  26. //
  27. // fahr = lower;
  28. //
  29. // printf("Fahrenheit\tCelcius\n");
  30. // while (fahr <= upper)
  31. // {
  32. // celcius = (5.0 / 9.0) * (fahr - 32.0); //5.0 for floating point number arithmetic
  33. // printf("%10.0f %12.1f\n", fahr, celcius);
  34. // fahr = fahr + step;
  35. // }
  36. // printf("\n\n\n\n\n\n\n\n\n\n\n");
  37. //}
  38.  
  39. //main()
  40. //{
  41. // float fahr, celcius;
  42. // int lower, upper, step;
  43. //
  44. // lower = 0;
  45. // upper = 300;
  46. // step = 20;
  47. //
  48. // celcius = lower;
  49. //
  50. // printf("Celcius \tFahrenheit\n");
  51. // while (celcius <= upper)
  52. // {
  53. // fahr = ((9.0 / 5.0) * (celcius)) + 32.0; //5.0 for floating point number arithmetic
  54. // printf("%7.0f %18.1f\n", celcius, fahr);
  55. // celcius = celcius + step;
  56. // }
  57. // printf("\n\n\n\n\n\n\n\n\n\n\n");
  58. //}
  59.  
  60. //main()
  61. //{
  62. // float fahr, celcius;
  63. // int lower, upper, step;
  64. //
  65. // lower = 0;
  66. // upper = 300;
  67. // step = 20;
  68. //
  69. // celcius = upper;
  70. //
  71. // printf("Celcius \tFahrenheit\n");
  72. // while (celcius >= lower)
  73. // {
  74. // fahr = ((9.0 / 5.0) * (celcius)) + 32.0; //5.0 for floating point number arithmetic
  75. // printf("%7.0f %18.1f\n", celcius, fahr);
  76. // celcius = celcius - step;
  77. // }
  78. // printf("\n\n\n\n\n\n\n\n\n\n\n");
  79. //}
  80.  
  81. //main()
  82. //{
  83. // int c;
  84. // while (c = (getchar() != EOF))
  85. // {
  86. // printf("%d\n", c);
  87. // }
  88. // printf("%d", c);
  89. //}
  90.  
  91. //#define BUFSIZE 100
  92. //char buf[BUFSIZE];
  93. //int bufp = 0;
  94. //
  95. //main()
  96. //{
  97. // int getch(void);
  98. // void ungetch(int);
  99. // int c;
  100. //
  101. // Start:
  102. // while (c = (getch() != EOF))
  103. // {
  104. // ungetch(); //c is 1, it returns a 1 to buf.
  105. // if (c = (getch() != '\n'))
  106. // {
  107. // ungetch(c);
  108. // if (c = (getch() != ' '))
  109. // {
  110. // printf("%d\n", c);
  111. // }
  112. // else
  113. // {
  114. // printf("skipped: <-\n");
  115. // }
  116. // }
  117. // else
  118. // {
  119. // printf("skipped: \\n <-\n");
  120. // }
  121. // }
  122. // printf("%d", c);
  123. // goto Start;
  124. //}
  125. //
  126. //int getch(void)
  127. //{
  128. // return (bufp > 0) ? buf[--bufp] : getchar();
  129. //}
  130. //void ungetch(int c)
  131. //{
  132. // if (bufp >= BUFSIZE) printf("ungetch: too many characters\n");
  133. // else
  134. // buf[bufp++] = c;
  135. //}
  136.  
  137. //main()
  138. //{
  139. // int c;
  140. //
  141. // if (c = (getchar() != EOF))
  142. // {
  143. // printf("if loop executed so c was 1 because getchar() was 1.\n");
  144. // printf("value of getchar(): %d\n\n", c);
  145. // }
  146. // else
  147. // {
  148. // printf("if loop exited so c was 0 because getchar() was 0.\n");
  149. // printf("value of getchar(): %d", c);
  150. // }
  151. //}
  152.  
  153. //main()
  154. //{
  155. // int c = EOF;
  156. // printf("%d\n", c);
  157. //}
  158.  
  159. //main()
  160. //{
  161. // int c;
  162. // int NumberOfNewLines = 0;
  163. // int NumberOfTabs = 0;
  164. // int NumberOfSpaces = 0;
  165. //
  166. //
  167. // while ((c = getchar()) != EOF)
  168. // {
  169. // if (c == '\n')
  170. // {
  171. // NumberOfNewLines++;
  172. // }
  173. // else if (c == '\t')
  174. // {
  175. // NumberOfTabs++;
  176. // }
  177. // else if (c == ' ')
  178. // {
  179. // NumberOfSpaces++;
  180. // }
  181. // }
  182. //
  183. // printf("Number of New Lines: %d\nNumber of Tabs: %d\nNumber of Spaces: %d\n", NumberOfNewLines, NumberOfTabs, NumberOfSpaces);
  184. //}
  185.  
  186. //main()
  187. //{
  188. // int c;
  189. // int OneSpaceRead = 0;
  190. //
  191. // while ((c = getchar()) != EOF)
  192. // {
  193. // if (c != ' ')
  194. // {
  195. // putchar(c);
  196. // OneSpaceRead = 0;
  197. // }
  198. // else if (c == ' ' && OneSpaceRead == 0)
  199. // {
  200. // putchar(c);
  201. // OneSpaceRead = 1;
  202. // }
  203. // }
  204. //}
  205.  
  206.  
  207. //main()
  208. //{
  209. // int c;
  210. //
  211. // while ((c = getchar()) != EOF)
  212. // {
  213. // if (c != '\n' && c != '\b' && c != '\t')
  214. // putchar(c);
  215. // else if (c == '\n')
  216. // {
  217. // printf("\\n");
  218. // }
  219. // else if (c == '\t')
  220. // {
  221. // printf("\\t");
  222. // }
  223. // else if (c == '\\')
  224. // {
  225. // printf("\\");
  226. // }
  227. // else if (c == '\b')
  228. // {
  229. // printf("backspace");
  230. // }
  231. // }
  232. //}
  233.  
  234. //main()
  235. //{
  236. // int c;
  237. // int InAWord = 0;
  238. //
  239. // printf("This program prints out every word and spacebar on an individual line.");
  240. //
  241. // while ((c = getchar()) != EOF)
  242. // {
  243. // if (c != ' ' && c != '\n')
  244. // {
  245. // putchar(c);
  246. // InAWord = 1;
  247. // }
  248. // if (c == ' ')
  249. // {
  250. // if (InAWord == 1)
  251. // {
  252. // printf("\n");
  253. // putchar(c);
  254. // printf("\n");
  255. // InAWord = 0;
  256. // }
  257. // else if (InAWord == 0)
  258. // {
  259. // putchar(c);
  260. // printf("\n");
  261. // }
  262. // }
  263. // if (c == '\n')
  264. // {
  265. // putchar(c);
  266. // }
  267. // }
  268. //}
  269.  
  270.  
  271. //main()
  272. //{
  273. // #define parameter 100
  274. // int c;
  275. // int NumberOfLetters[parameter];
  276. // int NumberOfLettersIndex = 0;
  277. //
  278. // int i = 0;
  279. // int indexForNumberOfLettersArray = 0;
  280. //
  281. // for (i = 0; i < parameter; i++)
  282. // {
  283. // NumberOfLetters[i] = 0;
  284. // }
  285. //
  286. // while ((c = getchar()) != EOF && c != '\n')
  287. // {
  288. // if (c != ' ' && c != '\n')
  289. // {
  290. // NumberOfLetters[NumberOfLettersIndex]++;
  291. // }
  292. // if (c == ' ')
  293. // {
  294. // NumberOfLettersIndex++;
  295. // NumberOfLetters[NumberOfLettersIndex]++;
  296. // NumberOfLettersIndex++;
  297. // }
  298. // }
  299. //
  300. // for (i = 0; i < parameter; i = i + 1)
  301. // {
  302. // if ((NumberOfLetters[i]) > 0)
  303. // {
  304. // while ((NumberOfLetters[i]) > 0)
  305. // {
  306. // printf("*");
  307. // NumberOfLetters[i]--;
  308. // }
  309. // printf("\n");
  310. // }
  311. // else if ((NumberOfLetters[i]) == 0)
  312. // break;
  313. // }
  314. //}
  315.  
  316. //#define MAXSIZE 100
  317. //#define IN 1
  318. //#define OUT 0
  319. //
  320. //main()
  321. //{
  322. // int c;
  323. // int MAXLETTERCOUNT = 0;
  324. // int WORDCOUNT = 0;
  325. // int i = 0;
  326. // int j;
  327. // int Array[MAXSIZE];
  328. // int State = OUT; //flag for whether in word or not
  329. // int Max[MAXSIZE];
  330. //
  331. // for (i = 0; i < MAXSIZE; i++) //i < MAXSIZE
  332. // {
  333. // Array[i] = 0;
  334. // Max[i] = 1;
  335. // }
  336. //
  337. // i = 0;//
  338. //
  339. // while ((c = getchar()) != EOF)
  340. // {
  341. // if (isalpha(c)) //isalphanumerical
  342. // {
  343. // State = IN;
  344. // Array[i]++;
  345. // Max[i]++;
  346. // if (Array[i] >= MAXLETTERCOUNT)
  347. // {
  348. // MAXLETTERCOUNT = Array[i];
  349. // }
  350. // }
  351. // else if (State == IN && (c == ' ' || c == '\t' || c == '\n'))
  352. // {
  353. // WORDCOUNT++;
  354. // i++;
  355. // State = OUT;
  356. // }
  357. // else
  358. // continue;
  359. // }
  360. //
  361. // for (i = MAXLETTERCOUNT + 1; i > 0; i--)
  362. // {
  363. // for (j = 0; j < WORDCOUNT; j++)
  364. // {
  365. // if (Max[j] == i)
  366. // {
  367. // printf("%5d", Max[j] - 1);
  368. // }
  369. // else if (Array[j] == i)
  370. // {
  371. // printf(" *");
  372. // Array[j]--;
  373. // }
  374. // else
  375. // {
  376. // printf(" ");
  377. // }
  378. // }
  379. // printf("\n");
  380. // }
  381. //
  382. // for (i = 1; i <= WORDCOUNT; i++)
  383. // printf("%5d", i);
  384. //
  385. // printf("\n");
  386. //}
  387.  
  388. //#define MAXSIZE 100
  389. //#define IN 1
  390. //#define OUT 0
  391. //
  392. //main()
  393. //{
  394. // int c;
  395. // int MAXLETTERCOUNT = 0;
  396. // int i = 0;
  397. // int j;
  398. // int nl = 0;
  399. // int Array[MAXSIZE];
  400. // int State = OUT; //flag for whether in word or not
  401. //
  402. // for (i = 0; i < MAXSIZE; i++) //i < MAXSIZE
  403. // {
  404. // Array[i] = 0;
  405. // }
  406. //
  407. // i = 0;//
  408. //
  409. // while ((c = getchar()) != EOF)
  410. // {
  411. // if (isalpha(c)) //isalphanumerical
  412. // {
  413. // State = IN;
  414. // nl++;
  415. // if (nl >= MAXLETTERCOUNT)
  416. // {
  417. // MAXLETTERCOUNT = nl;
  418. // }
  419. // }
  420. // else if (State == IN && (c == ' ' || c == '\t' || c == '\n'))
  421. // {
  422. // Array[nl]++;
  423. // nl = 0;
  424. // State = OUT;
  425. // }
  426. // else
  427. // continue;
  428. // }
  429. //
  430. // for (i = 1; i <= MAXLETTERCOUNT; i++)
  431. // printf("%5d", Array[i]);
  432. //
  433. // printf("\n");
  434. //
  435. // for (i = 1; i <= MAXLETTERCOUNT; i++)
  436. // printf("%5d", i);
  437. //
  438. // printf("\n");
  439. //}
  440.  
  441. //double toCelcius(double);
  442. //
  443. ////main()
  444. ////{
  445. //// int c;
  446. //// while ((c = getchar()) != EOF)
  447. //// {
  448. ////
  449. //// }
  450. ////
  451. ////}
  452. //
  453. //main()
  454. //{
  455. // int i = 0;
  456. // while (i <= 212)
  457. // {
  458. // printf("%9.4f\n", toCelcius(i));
  459. // i++;
  460. // }
  461. //
  462. //}
  463. //
  464. //double toCelcius(double F)
  465. //{
  466. // double C;
  467. // C = (5.0 / 9.0) * (F - 32);
  468. // return C;
  469. //}
  470.  
  471. //#define MAXLINE 1000
  472.  
  473. //int getline(char line[], int maxline);
  474. //void copy(char from[], char to[]);
  475. //
  476. //main()
  477. //{
  478. // int len;
  479. // int max = 0;
  480. // char line[MAXLINE];
  481. // char longest[MAXLINE];
  482. //
  483. // while ((len = getline(line, MAXLINE)) > 0)
  484. // {
  485. // if (len > max)
  486. // {
  487. // max = len;
  488. // copy(line, longest);
  489. // }
  490. // }
  491. // if (max > 0)
  492. // printf("%s", longest);
  493. // return 0;
  494. //}
  495. //
  496. //int getline(char s[], int limit)
  497. //{
  498. // int i;
  499. // int c;
  500. //
  501. // for (i = 0; i < limit - 1 && (c = getchar()) != EOF && c != '\n'; i++)
  502. // {
  503. // s[i] = c;
  504. // }
  505. // if (c == '\n')
  506. // {
  507. // s[i] = c;
  508. // i++;
  509. // }
  510. // s[i] = '\0';
  511. // return i;
  512. //}
  513. //
  514. //void copy(char from[], char to[])
  515. //{
  516. // int i = 0;
  517. // while ((to[i] = from[i]) != '\0')
  518. // {
  519. // i++;
  520. // }
  521. //}
  522.  
  523. //main()
  524. //{
  525. // int i = 0;
  526. // int nc = 0;
  527. // int limit = 0;
  528. // int c;
  529. // char array[MAXLINE];
  530. // for (limit = 0; limit < 100; limit++)
  531. // {
  532. // i = 0;
  533. // while ((c = getchar()) != EOF && c != '\n' && i < MAXLINE - 1)
  534. // {
  535. // array[i] = c;
  536. // i++;
  537. // nc++;
  538. // }
  539. // array[i] = '\0';
  540. // //i = 0;
  541. // printf("%s %d\n", array, nc);
  542. // nc = 0;
  543. // }
  544. //}
  545.  
  546. //main()
  547. //{
  548. // int i = 0; D
  549. // int nc = 0; O
  550. // int limit = 0; E
  551. // int c; S
  552. // int array[MAXLINE];
  553. // while ((c = getchar()) != EOF && c != '\n' && limit < 100) N
  554. // { O
  555. // array[i] = c; T
  556. // i++;
  557. // nc++; W
  558. // } O
  559. // array[i] = '\0'; R
  560. // i = 0; K
  561. // printf("%s %d\n", array, nc);
  562. //}
  563.  
  564. //main()
  565. //{
  566. // int i = 0;
  567. // int nc = 0;
  568. // int limit = 0;
  569. // int max = 0;
  570. // int c;
  571. // char array[MAXLINE];
  572. // char longest[MAXLINE];
  573. // for (limit = 0; limit < 100; limit++)
  574. // {
  575. // i = 0;
  576. // while ((c = getchar()) != EOF && c != '\n' && i < MAXLINE - 1)
  577. // {
  578. // array[i] = c;
  579. // i++;
  580. // nc++;
  581. // }
  582. // array[i] = '\0';
  583. // i = 0;
  584. // if (nc > max)
  585. // {
  586. // max = nc;
  587. // while ((longest[i] = array[i]) != '\0')
  588. // i++;
  589. // }
  590. // //i = 0;
  591. // if (c == EOF)
  592. // printf("%s %d\n", longest, max);
  593. // nc = 0;
  594. // }
  595. //}
  596.  
  597. //main()
  598. //{
  599. // int i = 0;
  600. // int nc = 0;
  601. // int limit = 0;
  602. // int c;
  603. // char array[MAXLINE];
  604. // for (limit = 0; limit < 100; limit++)
  605. // {
  606. // i = 0;
  607. // while ((c = getchar()) != EOF && c != '\n' && i < MAXLINE - 1)
  608. // {
  609. // array[i] = c;
  610. // i++;
  611. // nc++;
  612. // }
  613. // array[i] = '\0';
  614. // //i = 0;
  615. // if (nc > 80)
  616. // printf("%s %d\n", array, nc);
  617. // nc = 0;
  618. // }
  619. //}
  620.  
  621. #define YES 1
  622. #define NO 0
  623.  
  624. //main()
  625. //{
  626. // int c;
  627. // char array[MAXLINE];
  628. // int INALINE = NO;
  629. // int TRAILING = NO;
  630. // int i = 0;
  631. // int index = 0;
  632. // int limit = 0;
  633. // int linesskipped = 0;
  634. // for (limit = 0; limit < 100; limit++)
  635. // {
  636. // while ((c = getchar()) != EOF && i < MAXLINE - 1)
  637. // {
  638. // if (c != '\n' && c != ' ' && c != '\t')
  639. // {
  640. // array[i] = c;
  641. // INALINE = YES;
  642. // TRAILING = NO;
  643. // i++;
  644. // }
  645. // if ((c == ' ' || c == '\t') && TRAILING == NO)
  646. // {
  647. // array[i] = c;
  648. // index = i;
  649. // TRAILING = YES;
  650. // i++;
  651. // }
  652. // else if ((c == ' ' || c == '\t') && TRAILING == YES)
  653. // {
  654. // array[i] = c;
  655. // i++;
  656. // }
  657. // if (c == '\n' && TRAILING == YES && INALINE == YES)
  658. // {
  659. // INALINE = NO;
  660. // TRAILING = NO;
  661. // array[index] = '\0';
  662. // array[index] = 'x';
  663. // array[index+1] = '\n';
  664. // i = index + 2;
  665. // }
  666. // else if (c == '\n' && TRAILING == NO && INALINE == YES)
  667. // {
  668. // INALINE = NO;
  669. // TRAILING = NO;
  670. // array[i] = 'x';
  671. // array[i+1] = '\n';
  672. // i = i + 2;
  673. // }
  674. // else if (c == '\n' && TRAILING == YES && INALINE == NO)
  675. // {
  676. // TRAILING = NO;
  677. // array[index] = '\0';
  678. // array[index] = 'x';
  679. // array[index + 1] = '\n';
  680. // i = index + 2;
  681. // }
  682. // }
  683. // if (c == EOF)
  684. // {
  685. // array[i] = '\0';
  686. // printf("%s", array);
  687. // array[0] = '\0';
  688. // i = 0;
  689. // }
  690. // }
  691. //}
  692.  
  693. //#define MAXLENGTH 10000
  694. //
  695. //void reverse(char[], char[], int length); //new reverse(s) on line 5295
  696. //
  697. //main()
  698. //{
  699. // int c;
  700. // int i = 0;
  701. // int SOMETHINGWASREVERSED = NO;
  702. // char array[MAXLENGTH];
  703. // char reversearray[MAXLENGTH];
  704. //
  705. // while ((c = getchar()) != '!' && i < MAXLENGTH - 1)
  706. // {
  707. // if (c == '\n' && SOMETHINGWASREVERSED == YES)
  708. // {
  709. // printf("\n");
  710. // SOMETHINGWASREVERSED = NO;
  711. // }
  712. // else if (c == '?')
  713. // {
  714. // SOMETHINGWASREVERSED = YES;
  715. // array[i] = '\0';
  716. // reverse(array, reversearray, i);
  717. // printf("%s", reversearray);
  718. // array[0] = '\0';
  719. // reversearray[0] = '\0';
  720. // i = 0;
  721. // }
  722. //
  723. // else
  724. // {
  725. // array[i] = c;
  726. // i++;
  727. // }
  728. // }
  729. // array[i] = '\0';
  730. // reverse(array, reversearray, i);
  731. // printf("%s\n", reversearray);
  732. //}
  733. //
  734. //void reverse(char from[], char to[], int length)
  735. //{
  736. // int i = 0;
  737. // while (length - 1 >= 0)
  738. // {
  739. // to[i] = from[length - 1];
  740. // length--;
  741. // i++;
  742. // }
  743. // to[i] = '\0';
  744. //}
  745.  
  746. //#define MAXSIZE 1000
  747. //
  748. //main()
  749. //{
  750. // int c;
  751. // int tabspaces = 0;
  752. // int spaces = 0;
  753. // int i = 0;
  754. // int nc = 0;
  755. // char array[MAXSIZE];
  756. //
  757. // printf("How many tab spaces? Type in the number of tab spaces and then press enter\n");
  758. //
  759. // while ((tabspaces = getchar()) == '\n')
  760. // ;
  761. //
  762. // while (tabspaces < '0' || tabspaces > '9')
  763. // {
  764. // printf("Not a number between 0 and 9.\nType in the number of tab spaces and then press enter\n");
  765. // while ((tabspaces = getchar()) == '\n')
  766. // ;
  767. // }
  768. // printf("Ok replacing text now. Press ^Z to print out replacement text. The number of tabspaces you selected is %d. Anything after %d has been stored in your replacement text.\n", tabspaces - '0', tabspaces - '0');
  769. // while ((c = getchar()) != EOF && i < MAXSIZE)
  770. // {
  771. // if (c != '\t' && c != '\n')
  772. // {
  773. // array[i] = c;
  774. // i++;
  775. // nc++;
  776. // }
  777. // else if (c == '\n')
  778. // {
  779. // array[i] = c;
  780. // i++;
  781. // nc = 0;
  782. // }
  783. // else if (c == '\t')
  784. // {
  785. // spaces = (tabspaces - '0') - (nc % (tabspaces - '0')); //tabspaces - '0'. The '8' stored in tabspaces from getchar is the integer/NUMERICAL value of the '8' in the ASCII chart/character code.
  786. // while (spaces > 0)
  787. // {
  788. // array[i] = 'x';
  789. // i++;
  790. // spaces--;
  791. // nc = 0; //NOTICED AND FIXED THIS PROGRAM WITH THIS EXPRESSION AFTER MOVING ON TO THE NEXT PROGRAM AND REALIZING THAT TWO CONTINUOUS INPUTS OF A TEST CONDITION WAS NOT TAKEN CARE OF! This resets the tab spaces logic.
  792. // }
  793. // }
  794. // }
  795. // array[i] = '\0';
  796. // printf("%s\n", array);
  797. //}
  798.  
  799. //inastringofspace
  800. //beginning of text
  801. //#define MAXSIZE 1000
  802. //main()
  803. //{
  804. // int c;
  805. // int i = 0;
  806. // int nc = 0;
  807. // int nfl = 0;
  808. // int Firsttab = 0;
  809. // int spacesfromtab = 0;
  810. // int stringspaces = 0;
  811. // int STRINGOFSPACES = NO;
  812. // char array[MAXSIZE];
  813. // while ((c = getchar()) != EOF && i < MAXSIZE - 1)
  814. // {
  815. // if (c != '\t' && c != ' ' && c != '\n')
  816. // {
  817. // if (STRINGOFSPACES == YES)
  818. // {
  819. // if (8 - (nfl % 8) <= stringspaces)
  820. // {
  821. // stringspaces = stringspaces - (8 - (nfl % 8));
  822. // array[i] = '\t';
  823. // i++;
  824. // nc = 0;
  825. // nfl = 0;
  826. // while (stringspaces / 8 > 0)
  827. // {
  828. // array[i] = '\t';
  829. // i++;
  830. // stringspaces = stringspaces - 8;
  831. // }
  832. // }
  833. // while (stringspaces > 0)
  834. // {
  835. // array[i] = 'y';
  836. // i++;
  837. // nc++;
  838. // stringspaces--;
  839. // nfl = 0;
  840. // }
  841. // }
  842. // STRINGOFSPACES = NO;
  843. // array[i] = c;
  844. // i++;
  845. // nc++;
  846. // nfl++;
  847. // }
  848. // else if (c == '\t')
  849. // {
  850. // STRINGOFSPACES = YES;
  851. // spacesfromtab = 8 - (nc % 8);
  852. // nc = 0;
  853. // stringspaces = stringspaces + spacesfromtab;
  854. // }
  855. // else if (c == ' ')
  856. // {
  857. // STRINGOFSPACES = YES;
  858. // stringspaces++;
  859. // nc++;
  860. // }
  861. // else if (c == '\n')
  862. // {
  863. // if (STRINGOFSPACES == YES)
  864. // {
  865. // if (8 - (nfl % 8) <= stringspaces)
  866. // {
  867. // stringspaces = stringspaces - (8 - (nfl % 8));
  868. // array[i] = '\t';
  869. // i++;
  870. // nc = 0;
  871. // nfl = 0;
  872. // while (stringspaces / 8 > 0)
  873. // {
  874. // array[i] = '\t';
  875. // i++;
  876. // stringspaces = stringspaces - 8;
  877. // }
  878. // }
  879. // while (stringspaces > 0)
  880. // {
  881. // array[i] = 'y';
  882. // i++;
  883. // nc++;
  884. // stringspaces--;
  885. // nfl = 0;
  886. // }
  887. // }
  888. // nc = 0;
  889. // nfl = 0;
  890. // STRINGOFSPACES = NO;
  891. // array[i] = c;
  892. // i++;
  893. // }
  894. // }
  895. //
  896. // if (STRINGOFSPACES == YES)
  897. // {
  898. // if (8 - (nfl % 8) <= stringspaces)
  899. // {
  900. // stringspaces = stringspaces - (8 - (nfl % 8));
  901. // array[i] = '\t';
  902. // i++;
  903. // nc = 0;
  904. // nfl = 0;
  905. // while (stringspaces / 8 > 0)
  906. // {
  907. // array[i] = '\t';
  908. // i++;
  909. // stringspaces = stringspaces - 8;
  910. // }
  911. // }
  912. // while (stringspaces > 0)
  913. // {
  914. // array[i] = 'y';
  915. // i++;
  916. // nc++;
  917. // stringspaces--;
  918. // nfl = 0;
  919. // }
  920. //
  921. // array[i] = '\0';
  922. // printf("%s\n", array);a
  923. //}
  924.  
  925. //#define MAXCHARACTERS 1000
  926. //main()
  927. //{
  928. // int c;
  929. // int i = 0;
  930. // int j = 0;
  931. // int nc = 0;
  932. // char array[MAXCHARACTERS];
  933. // char output[MAXCHARACTERS];
  934. // while ((c = getchar()) != EOF)
  935. // {
  936. // array[i++] = c;
  937. // }
  938. // array[i] = '\0';
  939. // i = 0;
  940. // while (array[i] != '\0')
  941. // {
  942. // while (nc < 9 && array[i] != '\0')
  943. // {
  944. // if (array[i] == '\t')
  945. // {
  946. // nc = nc + 8 - (nc % 8);
  947. // if (nc > 9)
  948. // {
  949. // output[j++] = '\n';
  950. // output[j++] = '\t';
  951. // nc = 8;
  952. // }
  953. // }
  954. // else if (array[i] != '\t')
  955. // nc++;
  956. // output[j] = array[i];
  957. // i++;
  958. // j++;
  959. // }
  960. //
  961. // if (nc == 9)
  962. // {
  963. // if (array[i] != ' ' && array[i] != '\t' && array[i] != '\n')
  964. // {
  965. // output[j++] = '-';
  966. // output[j++] = '\n';
  967. // nc = 0;
  968. // }
  969. // else
  970. // {
  971. // output[j++] = '\n';
  972. // nc = 0;
  973. // }
  974. // }
  975. // }
  976. // output[j] = '\0';
  977. // printf("%s\n", output);
  978. //}
  979.  
  980. //#define MAXCHARACTERS 1000
  981. //main()
  982. //{
  983. // int c;
  984. // int i = 0;
  985. // int j = 0;
  986. // int k = 0;
  987. // int nc = 1;
  988. // int counter = 1;
  989. // char array[MAXCHARACTERS];
  990. // char output[MAXCHARACTERS];
  991. // while ((c = getchar()) != EOF)
  992. // {
  993. // array[i++] = c;
  994. // }
  995. // array[i] = '\0';
  996. // i = 0;
  997. //
  998. // while (array[i] != '\0')
  999. // {
  1000. // while (counter < 9 && array[i] != '\0')
  1001. // {
  1002. // if (array[i] == '\t')
  1003. // {
  1004. // k = 8 - nc % 8;
  1005. // while (k >= 0)
  1006. // {
  1007. // output[j++] = ' ';
  1008. // k--;
  1009. // counter++;
  1010. // nc++;
  1011. // }
  1012. // i++;
  1013. // }
  1014. // else if (array[i] != '\t' && array[i] != '\n')
  1015. // {
  1016. // output[j] = array[i];
  1017. // i++;
  1018. // j++;
  1019. // nc++;
  1020. // counter++;
  1021. // }
  1022. // else if (array[i] == '\n')
  1023. // {
  1024. // output[j] = array[i];
  1025. // i++;
  1026. // j++;
  1027. // nc = 1;
  1028. // counter = 1;
  1029. // }
  1030. // }
  1031. // if (counter >= 9)
  1032. // {
  1033. // if (array[i] != ' ' && array[i] != '\t' && array[i] != '\n' && array[i+1] != ' ' && array[i+1] != '\t' && array[i+1] != '\n')
  1034. // {
  1035. // output[j] = array[i];
  1036. // i++;
  1037. // j++;
  1038. // output[j++] = '-';
  1039. // output[j++] = '\n';
  1040. // nc++;
  1041. // counter = 1;
  1042. // }
  1043. // else if (array[i] == '\t')
  1044. // {
  1045. // output[j++] = '\n';
  1046. // output[j++] = '\t';
  1047. // i++;
  1048. // nc++;
  1049. // counter = 8;
  1050. // }
  1051. // else if (array[i] == ' ')
  1052. // {
  1053. // output[j++] = ' ';
  1054. // output[j++] = '\n';
  1055. // i++;
  1056. // nc++;
  1057. // counter = 1;
  1058. //
  1059. // }
  1060. // else if (array[i] == '\n')
  1061. // {
  1062. // output[j] = array[i];
  1063. // i++;
  1064. // j++;
  1065. // nc = 1;
  1066. // counter = 1;
  1067. // }
  1068. // else
  1069. // {
  1070. // output[j] = array[i];
  1071. // i++;
  1072. // j++;
  1073. // output[j++] = '\n';
  1074. // nc++;
  1075. // counter = 1;
  1076. // }
  1077. // }
  1078. // }
  1079. //
  1080. // output[j] = '\0';
  1081. // printf("%s\n", output);
  1082. //}
  1083. //#define MAXARRAYSIZE 1000
  1084. //#define ON 1
  1085. //#define OFF 0
  1086. //main()
  1087. //{
  1088. // int c;
  1089. // char array[MAXARRAYSIZE];
  1090. // int i = 0;
  1091. // int j = 0;
  1092. // char output[MAXARRAYSIZE];
  1093. // int DONE = NO;
  1094. // int STAR = NO;
  1095. // int COMMENTCHECKING = ON;
  1096. //
  1097. // while ((c = getchar()) != EOF && i < MAXARRAYSIZE - 1)
  1098. // {
  1099. // array[i] = c;
  1100. // i++;
  1101. // }
  1102. // array[i] = '\0';
  1103. // i = 0;
  1104. // while (array[i] != '\0')
  1105. // {
  1106. // while (COMMENTCHECKING == ON && array[i] != '\0')
  1107. // {
  1108. // output[j] = array[i];
  1109. // if (array[i] == '/' && COMMENTCHECKING == YES)
  1110. // {
  1111. // if (array[i + 1] == '/')
  1112. // {
  1113. // i++;
  1114. // while (array[i] != '\n')
  1115. // {
  1116. // i++;
  1117. // }
  1118. // output[j] = array[i];
  1119. // }
  1120. // else if (array[i + 1] == '*' && COMMENTCHECKING == YES)
  1121. // {
  1122. // i++;
  1123. // while (DONE == NO)
  1124. // {
  1125. // if (array[i] == '*')
  1126. // {
  1127. // STAR = YES;
  1128. // i++;
  1129. // }
  1130. // else if (array[i] == '/' && STAR == YES)
  1131. // {
  1132. // DONE = YES;
  1133. // i++;
  1134. // }
  1135. // else
  1136. // {
  1137. // STAR = NO;
  1138. // i++;
  1139. // }
  1140. // output[j] = array[i];
  1141. // }
  1142. // }
  1143. // }
  1144. // else if (array[i] == '"')
  1145. // {
  1146. // COMMENTCHECKING = OFF;
  1147. // }
  1148. // i++;
  1149. // j++;
  1150. // }
  1151. // while (COMMENTCHECKING == OFF && array[i] != '\0')
  1152. // {
  1153. // output[j] = array[i];
  1154. // i++;
  1155. // j++;
  1156. // if (array[i] == '"')
  1157. // {
  1158. // COMMENTCHECKING = ON;
  1159. // }
  1160. // }
  1161. // }
  1162. // output[j] = array[i];
  1163. // printf("%s\n", output);
  1164. //}
  1165. //#define MAXARRAYSIZE 10000
  1166. //#define ON 1
  1167. //#define OFF 0
  1168. //main()
  1169. //{ //test
  1170. // int c;
  1171. // char array[MAXARRAYSIZE]; /*test*/
  1172. // int i = 0;
  1173. // int j = 0;
  1174. // char output[MAXARRAYSIZE];
  1175. // int COMMENT = NO;
  1176. // int STAR = NO;
  1177. // int SQCOMMENTCHECKING = ON;
  1178. // int DQCOMMENTCHECKING = ON;
  1179. // /*test
  1180. // a
  1181. // b
  1182. // c*/
  1183. // while ((c = getchar()) != EOF && i < MAXARRAYSIZE - 1)
  1184. // {
  1185. // array[i] = c;
  1186. // i++;
  1187. // }
  1188. // array[i] = '\0';
  1189. // i = 0; //test
  1190. // while (array[i] != '\0') /*test
  1191. // a
  1192. // b
  1193. // c*/
  1194. // {
  1195. // while (SQCOMMENTCHECKING == ON && DQCOMMENTCHECKING == ON && array[i] != '\0')
  1196. // {
  1197. // output[j] = array[i];
  1198. // if (array[i] == '/' && SQCOMMENTCHECKING == ON && DQCOMMENTCHECKING == ON)
  1199. // {
  1200. // if (array[i + 1] == '/')
  1201. // {
  1202. // i++;
  1203. // while (array[i] != '\n')
  1204. // {
  1205. // i++;
  1206. // }
  1207. // output[j] = array[i];//test
  1208. // }
  1209. // else if (array[i + 1] == '*' && SQCOMMENTCHECKING == ON && DQCOMMENTCHECKING == ON)
  1210. // {
  1211. // i++;
  1212. // i++;
  1213. // COMMENT = YES;
  1214. // while (COMMENT == YES)
  1215. // {//test
  1216. // if (array[i] == '*')
  1217. // {
  1218. // STAR = YES;
  1219. // i++;//test
  1220. // } /*test
  1221. // a
  1222. // b
  1223. // c*/
  1224. // else if (array[i] == '/' && STAR == YES)
  1225. // {
  1226. // COMMENT = NO;
  1227. // i++;
  1228. // }
  1229. // else
  1230. // {
  1231. // STAR = NO;//test
  1232. // i++;
  1233. // }
  1234. // }
  1235. // //output[j] = array[i];
  1236. // }
  1237. // }
  1238. // /*else if (array[i] == '"' && array[i-1] != '\'')
  1239. // {
  1240. // output[j] = array[i];
  1241. // i++;
  1242. // j++;
  1243. // COMMENTCHECKING = OFF;
  1244. // }*/
  1245. // else if (array[i] == '\'' && array[i - 1] != '\\')
  1246. // {
  1247. // output[j] = array[i];
  1248. // i++;
  1249. // j++;
  1250. // SQCOMMENTCHECKING = OFF;
  1251. // }
  1252. // else if (array[i] == '"' && array[i - 1] != '\\')
  1253. // {
  1254. // output[j] = array[i];
  1255. // i++;
  1256. // j++;
  1257. // DQCOMMENTCHECKING = OFF;
  1258. // }
  1259. // else
  1260. // {
  1261. // i++;
  1262. // j++;
  1263. // }
  1264. // }
  1265. // while ((SQCOMMENTCHECKING == OFF || DQCOMMENTCHECKING == OFF) && array[i] != '\0')
  1266. // {
  1267. // if (array[i] == '\'' && array[i - 1] != '\\')
  1268. // {
  1269. // output[j] = array[i];
  1270. // i++;
  1271. // j++;
  1272. // SQCOMMENTCHECKING = ON;
  1273. // }
  1274. // else if (array[i] == '"' && array[i - 1] != '\\')
  1275. // {
  1276. // output[j] = array[i];
  1277. // i++;
  1278. // j++;
  1279. // DQCOMMENTCHECKING = ON;
  1280. // }
  1281. // else
  1282. // {
  1283. // output[j] = array[i];
  1284. // i++;
  1285. // j++;
  1286. // }
  1287. // // if (array[i] == '"')
  1288. // // { /*test
  1289. // //a
  1290. // //b
  1291. // //c*//*test*///
  1292. // // COMMENTCHECKING = ON;
  1293. // // }
  1294. // }
  1295. // }
  1296. // output[j] = array[i];
  1297. // printf("%s\n", output);
  1298. //}
  1299. #define MAXARRAYSIZE 10000
  1300.  
  1301.  
  1302. //main()
  1303. //{
  1304. // int c;
  1305. // char array[MAXARRAYSIZE];
  1306. // int i = 0;
  1307. // char output[MAXARRAYSIZE];
  1308. // int j = 0;
  1309. // int MAXLParenthesis = 0;
  1310. // int MAXLBraces = 0;
  1311. // int MAXLBrackets = 0;
  1312. // int RParenthesis = 0;
  1313. // int RBraces = 0;
  1314. // int RBrackets = 0;
  1315. // int COMMENT = NO;
  1316. // int STAR = NO;
  1317. // int COMMENTDONE = NO;
  1318. // int COMMENTBEGANON = 0;
  1319. // int COMMENTBEGANON_REGISTERED = NO;
  1320. // int LINE = 0;
  1321. // int UNEVENCOMMENT = NO;
  1322. // int INACOMMENT = NO;
  1323. // while ((c = getchar()) != EOF)
  1324. // {
  1325. // array[i] = c;
  1326. // i++;
  1327. // }
  1328. // array[i] = '\0';
  1329. // i = 0;
  1330. // while (array[i] != '\0')
  1331. // {
  1332. // if (array[i] == '\n')
  1333. // {
  1334. // LINE++; //LINE COUNTER
  1335. // } //THE NEWLINE IS SAVED IN THE NEXT EXPRESSION AND THEN IT DOES NOT FIT ANY OTHER CONDITIONAL STATEMENTS SO IT WILL BE INCREMENTED BY AN ELSE 1
  1336. //
  1337. // output[j] = array[i]; //STORES EVERY CHARACTER FROM array
  1338. //
  1339. // if (array[i] == ';') //THIS CHECKS FOR COMMENTS AFTER ;
  1340. // {
  1341. // i++;
  1342. // j++;
  1343. // output[j] = array[i]; //CHECKS EITHER // OR /* OR / OR WHITE SPACE OR NEWLINE . FIVE DIFFERENT CASES.
  1344. //
  1345. // while (array[i] != '\n') //WHILE THE CHARACTER WE JUST SAVED IS NOT THE NEW LINE \n CHECK THE SIX CASES
  1346. // {
  1347. // i++;
  1348. // j++;
  1349. // output[j] = array[i];
  1350. // if (INACOMMENT == NO && array[i] != '/' && array[i] != '*' && array[i] != ' ' && array[i] != '\t')
  1351. // {
  1352. // while (array[i] != '\n')
  1353. // {
  1354. // i++;
  1355. // j++;
  1356. // output[j] = array[i]; // //CASE 6 TEXT NOT IN A COMMENT
  1357. // }
  1358. // printf("Error: Syntax error. Text not in a comment on line %d.", LINE);
  1359. // }
  1360. //
  1361. // if (array[i] == '/') //CHECKS CASE 1 2 3 4 5
  1362. // {
  1363. // UNEVENCOMMENT = YES; //CASE 1 UNEVEN COMMENT
  1364. // INACOMMENT == YES;
  1365. // COMMENTBEGANON = LINE;
  1366. // if (array[i + 1] == '/')
  1367. // {
  1368. // UNEVENCOMMENT = NO;
  1369. // INACOMMENT = YES;
  1370. // while (array[i] != '\n')
  1371. // {
  1372. // i++;
  1373. // j++;
  1374. // output[j] = array[i]; //CASE 4 SINGLE LINE COMMENT //
  1375. // }
  1376. // }
  1377. //
  1378. // else if (array[i + 1] == '*') //CASE 5 MULTI LINE COMMENT /*
  1379. // {
  1380. // UNEVENCOMMENT = NO;
  1381. // INACOMMENT = YES;
  1382. // while (INACOMMENT == YES && array[i] != '\0')
  1383. // {
  1384. // if (array[i] == '\n')
  1385. // {
  1386. // if (COMMENTBEGANON_REGISTERED == NO)
  1387. // {
  1388. // COMMENTBEGANON = LINE;
  1389. // COMMENTBEGANON_REGISTERED == YES;
  1390. // }
  1391. // LINE++; //LINE COUNTER
  1392. // }
  1393. // if (array[i] == '*')
  1394. // {
  1395. // output[j] == array[i];
  1396. // j++;
  1397. // i++;
  1398. // STAR = YES;
  1399. // }
  1400. // else if (array[i] == '/' && STAR == YES)
  1401. // {
  1402. // output[j] == array[i];
  1403. // j++;
  1404. // i++;
  1405. // INACOMMENT = NO;
  1406. // COMMENTBEGANON_REGISTERED == NO;
  1407. // }
  1408. // else
  1409. // {
  1410. // output[j] == array[i];
  1411. // j++;
  1412. // i++;
  1413. // STAR = NO;
  1414. // }
  1415. // }
  1416. // printf(" End of multi line comment. New line will be printed v \n");
  1417. // }
  1418. // }
  1419. // }
  1420. // if (UNEVENCOMMENT == YES)
  1421. // {
  1422. // printf("Error: Unbalanced comment on line. Missing / or *.");
  1423. // output[j] = array[i];
  1424. // i++;
  1425. // j++;
  1426. // }
  1427. // else if (UNEVENCOMMENT == NO) //CASE 2 WHITESPACE //CASE 3 NEWLINE
  1428. // {
  1429. // output[j] = array[i];
  1430. // i++;
  1431. // j++;
  1432. // }
  1433. // }
  1434. // if (array[i] == '/')
  1435. // {
  1436. // if (array[i + 1] == '/')
  1437. // {
  1438. // output[j] == 'C';
  1439. // j++;
  1440. // output[j] == 'O';
  1441. // j++;
  1442. // output[j] == 'M';
  1443. // j++;
  1444. // output[j] == 'M';
  1445. // j++;
  1446. // output[j] == 'E';
  1447. // j++;
  1448. // output[j] == 'N';
  1449. // j++;
  1450. // output[j] == 'T';
  1451. // j++;
  1452. // output[j] == ':';
  1453. // j++;
  1454. // output[j] = array[i]; // /
  1455. // i++;
  1456. // j++;
  1457. // output[j] = array[i]; // //
  1458. // i++;
  1459. // j++;
  1460. // COMMENT = YES;
  1461. // while (c != '\n')
  1462. // {
  1463. // output[j] = array[i];//comment text
  1464. // i++;
  1465. // j++;
  1466. // }
  1467. // //output[j] = array[i]; //\n
  1468. // //i++;
  1469. // //j++;
  1470. // }
  1471. // else if (array[i + 1] == '*')
  1472. // {
  1473. // output[j] == 'C';
  1474. // j++;
  1475. // output[j] == 'O';
  1476. // j++;
  1477. // output[j] == 'M';
  1478. // j++;
  1479. // output[j] == 'M';
  1480. // j++;
  1481. // output[j] == 'E';
  1482. // j++;
  1483. // output[j] == 'N';
  1484. // j++;
  1485. // output[j] == 'T';
  1486. // j++;
  1487. // output[j] == ':';
  1488. // j++;
  1489. // output[j] = array[i]; // /
  1490. // i++;
  1491. // j++;
  1492. // output[j] = array[i]; // //
  1493. // i++;
  1494. // j++;
  1495. // COMMENT = YES;
  1496. // COMMENTBEGANON = LINE; //comment that began on Line 1 never terminated.
  1497. // while (COMMENTDONE == NO && array[i] != '\0')
  1498. // {
  1499. // if (array[i] == '*')
  1500. // {
  1501. // output[j] == array[i];
  1502. // j++;
  1503. // i++;
  1504. // STAR = YES;
  1505. // }
  1506. // else if (array[i] == '/' && STAR == YES)
  1507. // {
  1508. // output[j] == array[i];
  1509. // j++;
  1510. // i++;
  1511. // COMMENTDONE = YES;
  1512. // }
  1513. // else
  1514. // {
  1515. // output[j] == array[i];
  1516. // j++;
  1517. // i++;
  1518. // STAR = NO;
  1519. // }
  1520. // }
  1521. // if (array[i] == '\0' && COMMENTDONE == NO)
  1522. // {
  1523. // printf("Error: Unbalanced cooment. The comment that started on Line %d never finished.", COMMENTBEGANON);
  1524. // }
  1525. // COMMENT = NO;
  1526. // }
  1527. // else
  1528. // ;
  1529. // }
  1530. // else
  1531. // {
  1532. // j++;
  1533. // i++;
  1534. // }
  1535. //
  1536. // }
  1537. // output[j] = '\0';
  1538. // printf("%s\n", output);
  1539. //}
  1540.  
  1541. //#define MAXARRAYSIZE 10000
  1542. //
  1543. //
  1544. //main()
  1545. //{
  1546. // int c;
  1547. // char array[MAXARRAYSIZE];
  1548. // int i = 0;
  1549. // char output[MAXARRAYSIZE];
  1550. // int j = 0;
  1551. // int MAXLParenthesis = 0;
  1552. // int MAXLBraces = 0;
  1553. // int MAXLBrackets = 0;
  1554. // int RParenthesis = 0;
  1555. // int RBraces = 0;
  1556. // int RBrackets = 0;
  1557. // int COMMENT = NO;
  1558. // int STAR = NO;
  1559. // int COMMENTDONE = NO;
  1560. // int COMMENTBEGANON = 0;
  1561. // int COMMENTBEGANON_REGISTERED = NO;
  1562. // int LINE = 0;
  1563. // int UNEVENCOMMENT = NO;
  1564. // int INACOMMENT = NO;
  1565. // while ((c = getchar()) != EOF)
  1566. // {
  1567. // array[i] = c;
  1568. // i++;
  1569. // }
  1570. // array[i] = '\0';
  1571. // i = 0;
  1572. // while (array[i] != '\0')
  1573. // {
  1574. // if (array[i] == '\n')
  1575. // {
  1576. // LINE++; //LINE COUNTER
  1577. // }
  1578. //
  1579. // output[j] = array[i]; //STORES EVERY CHARACTER FROM array to output
  1580. //
  1581. // if (array[i] == ';') //THIS CHECKS FOR COMMENTS AND TEXT OUTSIDE OF COMMENTS AFTER ;
  1582. // {
  1583. // i++;
  1584. // j++;
  1585. //
  1586. // output[j] = array[i]; //CHECKS EITHER // OR /* OR / OR WHITE SPACE OR NEWLINE OR TEXT. SIX DIFFERENT CASES.
  1587. //
  1588. // while (array[i] != '\n') //CHECK THE SIX CASES
  1589. // {
  1590. // i++;
  1591. // j++;
  1592. //
  1593. // output[j] = array[i]; //BEGIINNING OF TEXT THAT HAS TO BE ANALYZED. SAVED AND NOT NEXT.
  1594. //
  1595. // if (INACOMMENT == NO && array[i] != '/' && array[i] != '*' && array[i] != ' ' && array[i] != '\t') //CASE 6
  1596. // {
  1597. // while (array[i] != '\n')
  1598. // {
  1599. // i++;
  1600. // j++;
  1601. //
  1602. // output[j] = array[i];
  1603. // }
  1604. // printf("Error: Syntax error. Text not in a comment on line %d.", LINE);
  1605. // }
  1606. //
  1607. // if (array[i] == '/') //CHECKS CASE 1 2 3 4 5
  1608. // {
  1609. // UNEVENCOMMENT = YES; //CASE 1 UNEVEN COMMENT
  1610. // INACOMMENT == YES;
  1611. // COMMENTBEGANON = LINE;
  1612. // if (array[i + 1] == '/')
  1613. // {
  1614. // UNEVENCOMMENT = NO;
  1615. // INACOMMENT = YES;
  1616. // while (array[i] != '\n')
  1617. // {
  1618. // i++;
  1619. // j++;
  1620. // output[j] = array[i]; //CASE 4 SINGLE LINE COMMENT //
  1621. // }
  1622. // }
  1623. //
  1624. // else if (array[i + 1] == '*') //CASE 5 MULTI LINE COMMENT /*
  1625. // {
  1626. // UNEVENCOMMENT = NO;
  1627. // INACOMMENT = YES;
  1628. // while (INACOMMENT == YES && array[i] != '\0')
  1629. // {
  1630. // if (array[i] == '\n')
  1631. // {
  1632. // if (COMMENTBEGANON_REGISTERED == NO)
  1633. // {
  1634. // COMMENTBEGANON = LINE;
  1635. // COMMENTBEGANON_REGISTERED == YES;
  1636. // }
  1637. // LINE++; //LINE COUNTER
  1638. // }
  1639. // if (array[i] == '*')
  1640. // {
  1641. // output[j] == array[i];
  1642. // j++;
  1643. // i++;
  1644. // STAR = YES;
  1645. // }
  1646. // else if (array[i] == '/' && STAR == YES)
  1647. // {
  1648. // output[j] == array[i];
  1649. // j++;
  1650. // i++;
  1651. // INACOMMENT = NO;
  1652. // COMMENTBEGANON_REGISTERED == NO;
  1653. // }
  1654. // else
  1655. // {
  1656. // output[j] == array[i];
  1657. // j++;
  1658. // i++;
  1659. // STAR = NO;
  1660. // }
  1661. // }
  1662. // printf(" End of multi line comment. New line will be printed v \n");
  1663. // }
  1664. // }
  1665. // }
  1666. // if (UNEVENCOMMENT == YES)
  1667. // {
  1668. // printf("Error: Unbalanced comment on line. Missing / or *.");
  1669. // output[j] = array[i];
  1670. // i++;
  1671. // j++;
  1672. // }
  1673. // else if (UNEVENCOMMENT == NO) //CASE 2 WHITESPACE //CASE 3 NEWLINE
  1674. // {
  1675. // output[j] = array[i];
  1676. // i++;
  1677. // j++;
  1678. // }
  1679. // }
  1680. // if (array[i] == '/')
  1681. // {
  1682. // if (array[i + 1] == '/')
  1683. // {
  1684. // output[j] == 'C';
  1685. // j++;
  1686. // output[j] == 'O';
  1687. // j++;
  1688. // output[j] == 'M';
  1689. // j++;
  1690. // output[j] == 'M';
  1691. // j++;
  1692. // output[j] == 'E';
  1693. // j++;
  1694. // output[j] == 'N';
  1695. // j++;
  1696. // output[j] == 'T';
  1697. // j++;
  1698. // output[j] == ':';
  1699. // j++;
  1700. // output[j] = array[i]; // /
  1701. // i++;
  1702. // j++;
  1703. // output[j] = array[i]; // //
  1704. // i++;
  1705. // j++;
  1706. // COMMENT = YES;
  1707. // while (c != '\n')
  1708. // {
  1709. // output[j] = array[i];//comment text
  1710. // i++;
  1711. // j++;
  1712. // }
  1713. // //output[j] = array[i]; //\n
  1714. // //i++;
  1715. // //j++;
  1716. // }
  1717. // else if (array[i + 1] == '*')
  1718. // {
  1719. // output[j] == 'C';
  1720. // j++;
  1721. // output[j] == 'O';
  1722. // j++;
  1723. // output[j] == 'M';
  1724. // j++;
  1725. // output[j] == 'M';
  1726. // j++;
  1727. // output[j] == 'E';
  1728. // j++;
  1729. // output[j] == 'N';
  1730. // j++;
  1731. // output[j] == 'T';
  1732. // j++;
  1733. // output[j] == ':';
  1734. // j++;
  1735. // output[j] = array[i]; // /
  1736. // i++;
  1737. // j++;
  1738. // output[j] = array[i]; // //
  1739. // i++;
  1740. // j++;
  1741. // COMMENT = YES;
  1742. // COMMENTBEGANON = LINE; //comment that began on Line 1 never terminated.
  1743. // while (COMMENTDONE == NO && array[i] != '\0')
  1744. // {
  1745. // if (array[i] == '*')
  1746. // {
  1747. // output[j] == array[i];
  1748. // j++;
  1749. // i++;
  1750. // STAR = YES;
  1751. // }
  1752. // else if (array[i] == '/' && STAR == YES)
  1753. // {
  1754. // output[j] == array[i];
  1755. // j++;
  1756. // i++;
  1757. // COMMENTDONE = YES;
  1758. // }
  1759. // else
  1760. // {
  1761. // output[j] == array[i];
  1762. // j++;
  1763. // i++;
  1764. // STAR = NO;
  1765. // }
  1766. // }
  1767. // if (array[i] == '\0' && COMMENTDONE == NO)
  1768. // {
  1769. // printf("Error: Unbalanced cooment. The comment that started on Line %d never finished.", COMMENTBEGANON);
  1770. // }
  1771. // COMMENT = NO;
  1772. // }
  1773. // else
  1774. // ;
  1775. // }
  1776. // else
  1777. // {
  1778. // j++;
  1779. // i++;
  1780. // }
  1781. //
  1782. // }
  1783. // output[j] = '\0';
  1784. // printf("%s\n", output);
  1785. //}
  1786. //
  1787. //
  1788. //if (array[i] == '/')
  1789. //{
  1790. // if (array[i + 1] == '/')
  1791. // {
  1792. // output[j] == 'C';
  1793. // j++;
  1794. // output[j] == 'O';
  1795. // j++;
  1796. // output[j] == 'M';
  1797. // j++;
  1798. // output[j] == 'M';
  1799. // j++;
  1800. // output[j] == 'E';
  1801. // j++;
  1802. // output[j] == 'N';
  1803. // j++;
  1804. // output[j] == 'T';
  1805. // j++;
  1806. // output[j] == ':';
  1807. // j++;
  1808. // output[j] = array[i]; // /
  1809. // i++;
  1810. // j++;
  1811. // output[j] = array[i]; // //
  1812. // i++;
  1813. // j++;
  1814. // COMMENT = YES;
  1815. // while (c != '\n')
  1816. // {
  1817. // output[j] = array[i];//comment text
  1818. // i++;
  1819. // j++;
  1820. // }
  1821. // //output[j] = array[i]; //\n
  1822. // //i++;
  1823. // //j++;
  1824. // }
  1825. // else if (array[i + 1] == '*')
  1826. // {
  1827. // output[j] == 'C';
  1828. // j++;
  1829. // output[j] == 'O';
  1830. // j++;
  1831. // output[j] == 'M';
  1832. // j++;
  1833. // output[j] == 'M';
  1834. // j++;
  1835. // output[j] == 'E';
  1836. // j++;
  1837. // output[j] == 'N';
  1838. // j++;
  1839. // output[j] == 'T';
  1840. // j++;
  1841. // output[j] == ':';
  1842. // j++;
  1843. // output[j] = array[i]; // /
  1844. // i++;
  1845. // j++;
  1846. // output[j] = array[i]; // //
  1847. // i++;
  1848. // j++;
  1849. // COMMENT = YES;
  1850. // COMMENTBEGANON = LINE; //comment that began on Line 1 never terminated.
  1851. // while (COMMENTDONE == NO && array[i] != '\0')
  1852. // {
  1853. // if (array[i] == '*')
  1854. // {
  1855. // output[j] == array[i];
  1856. // j++;
  1857. // i++;
  1858. // STAR = YES;
  1859. // }
  1860. // else if (array[i] == '/' && STAR == YES)
  1861. // {
  1862. // output[j] == array[i];
  1863. // j++;
  1864. // i++;
  1865. // COMMENTDONE = YES;
  1866. // }
  1867. // else
  1868. // {
  1869. // output[j] == array[i];
  1870. // j++;
  1871. // i++;
  1872. // STAR = NO;
  1873. // }
  1874. // }
  1875. // if (array[i] == '\0' && COMMENTDONE == NO)
  1876. // {
  1877. // printf("Error: Unbalanced cooment. The comment that started on Line %d never finished.", COMMENTBEGANON);
  1878. // }
  1879. // COMMENT = NO;
  1880. // }
  1881. // else
  1882. // ;
  1883. //}
  1884. //else
  1885. //{
  1886. // j++;
  1887. // i++;
  1888. //}
  1889. //
  1890. //collects everything, line counts, all errors after ; prototype done, comment prototyp done, single quote and double quote prototype done, bracket prototype done, parenthesis prototype done, braces prototype,
  1891.  
  1892. //#define MAXARRAYSIZE 10000
  1893. //main()
  1894. //{
  1895. // int c;
  1896. // char array[MAXARRAYSIZE];
  1897. // int i = 0;
  1898. // char output[MAXARRAYSIZE];
  1899. // int j = 0;
  1900. // char syntaxerror[MAXARRAYSIZE];
  1901. // int k = 0;
  1902. // int LeftBrackets = 0;
  1903. // int RightBrackets = 0;
  1904. // int EXTRABRACKETONLINE = 0;
  1905. // int RightParenthesis = 0;
  1906. // int LeftParanthesis = 0;
  1907. // int EXTRAPARENTHESISONLINE = 0;
  1908. // int RightBraces = 0;
  1909. // int LeftBraces = 0;
  1910. // int EXTRABRACESONLINE = 0;
  1911. // int STAR = NO;
  1912. // int UNBALANCEDCOMMENT = NO;
  1913. // int INACOMMENT = NO;
  1914. // int COMMENTDONE = NO;
  1915. // int COMMENTBEGANON = 0;
  1916. // int COMMENTENDEDON = 0;
  1917. // int LINE = 1;
  1918. // int SYNTAXERROR = NO;
  1919. // int SYNTAXERRORONLINE = 0;
  1920. // int INASINGLEQUOTE = NO;
  1921. // int INADOUBLEQUOTE = NO;
  1922. // int SINGLEQUOTEBEGANON = 0;
  1923. // int DOUBLEQUOTEBEGANON = 0;
  1924. // while ((c = getchar()) != EOF)
  1925. // {
  1926. // array[i] = c;
  1927. // i++;
  1928. // }
  1929. // array[i] = '\0';
  1930. // i = 0;
  1931. // while (array[i] != '\0' && array[i] != EOF)
  1932. // {
  1933. //
  1934. // if (array[i] == '\n')
  1935. // {
  1936. // LINE++; //LINE COUNTER
  1937. // if (LeftParanthesis > RightParenthesis)
  1938. // {
  1939. // printf("Error: Uneven Left Parenthesis. An extra ( was found on line %d. \t", EXTRAPARENTHESISONLINE);
  1940. // }
  1941. // RightBrackets = 0;
  1942. // LeftBrackets = 0;
  1943. // }
  1944. //
  1945. // output[j] = array[i]; //STORES EVERY CHARACTER FROM array
  1946. //
  1947. // if (array[i] == ';') //THIS CHECKS FOR COMMENTS AFTER ;
  1948. // {
  1949. // i++;
  1950. // j++;
  1951. //
  1952. // output[j] = array[i]; //CHECKS EITHER // OR /* OR / OR WHITE SPACE OR NEWLINE . SIX DIFFERENT CASES.
  1953. // if (LeftParanthesis > RightParenthesis)
  1954. // {
  1955. // printf("Error: Uneven Left Parenthesis. An extra ( was found on line %d. \n", EXTRAPARENTHESISONLINE);
  1956. // }
  1957. // RightBrackets = 0;
  1958. // LeftBrackets = 0;
  1959. //
  1960. // while (array[i] != '\n' && array[i] != '\0') //WHILE THE CHARACTER WE JUST SAVED IS NOT THE NEW LINE \n CHECK THE SIX CASES
  1961. // {
  1962. // if (INACOMMENT == NO && array[i] != '/' && array[i] != '*' && array[i] != ' ' && array[i] != '\t') //CASE 6
  1963. // {
  1964. // while (array[i] != '/' && array[i] != '\n' && array[i] != '\0')
  1965. // {
  1966. // output[j] = array[i];
  1967. // syntaxerror[k] = array[i];
  1968. // SYNTAXERRORONLINE = LINE;
  1969. // k++;
  1970. // i++;
  1971. // j++;
  1972. // }
  1973. // SYNTAXERROR = YES; //CASE 6 DONE
  1974. // }
  1975. //
  1976. // else if (array[i] == '/') //CASE 1 2 3 4 5
  1977. // {
  1978. // output[j] = array[i];
  1979. //
  1980. // UNBALANCEDCOMMENT = YES; //CASE 1 DONE
  1981. //
  1982. // COMMENTBEGANON = LINE;
  1983. //
  1984. // if (array[i + 1] == '/') //CASE 4
  1985. // {
  1986. // UNBALANCEDCOMMENT = NO;
  1987. // INACOMMENT = YES;
  1988. // while (array[i] != '\n')
  1989. // {
  1990. // i++;
  1991. // j++;
  1992. // output[j] = array[i]; //CASE 4 DONE
  1993. // }
  1994. // INACOMMENT = NO;
  1995. // }
  1996. //
  1997. // else if (array[i + 1] == '*') //CASE 5
  1998. // {
  1999. // UNBALANCEDCOMMENT = YES;
  2000. // INACOMMENT = YES;
  2001. // COMMENTBEGANON = LINE;
  2002. // i++;
  2003. // j++;
  2004. // output[j] = array[i];
  2005. // i++;
  2006. // j++;
  2007. // while (INACOMMENT == YES && array[i] != '\0')
  2008. // {
  2009. // if (array[i] == '\n')
  2010. // {
  2011. // LINE++; //LINE COUNTER
  2012. // }
  2013. // else if (array[i] == '*')
  2014. // {
  2015. // output[j] = array[i];
  2016. // i++;
  2017. // j++;
  2018. // STAR = YES;
  2019. // }
  2020. // else if (array[i] == '/' && STAR == YES)
  2021. // {
  2022. // output[j] = array[i];
  2023. // i++;
  2024. // j++;
  2025. // INACOMMENT = NO;
  2026. // UNBALANCEDCOMMENT = NO;
  2027. // COMMENTENDEDON = LINE;
  2028. // STAR = NO;
  2029. // }
  2030. // else
  2031. // {
  2032. // output[j] = array[i];
  2033. // i++;
  2034. // j++;
  2035. // STAR = NO;
  2036. // }
  2037. // }
  2038. // if (INACOMMENT == NO && UNBALANCEDCOMMENT == NO)
  2039. // {
  2040. // printf("Multi-line comment that started on line %d and ended on %d. New line.\n", COMMENTBEGANON, COMMENTENDEDON); //CASE 5 DONE
  2041. // }
  2042. // }
  2043. //
  2044. // else
  2045. // {
  2046. // while (array[i] != '\n')
  2047. // {
  2048. // syntaxerror[k] = array[i]; // / a b
  2049. // i++;
  2050. // j++;
  2051. // k++;
  2052. // if (array[i] != '\n')
  2053. // {
  2054. // output[j] = array[i]; // a b
  2055. // }
  2056. // SYNTAXERRORONLINE = LINE;
  2057. // }
  2058. // SYNTAXERROR = YES;
  2059. // }
  2060. // }
  2061. // else
  2062. // {
  2063. // i++;
  2064. // j++;
  2065. // }
  2066. // }
  2067. //
  2068. // if (UNBALANCEDCOMMENT == YES) //CASE 1
  2069. // {
  2070. // printf("Error: Unbalanced comment on line %d. Missing / or *.\n", COMMENTBEGANON);
  2071. // output[j] = array[i];
  2072. //
  2073. // if (array[i] == '\n')
  2074. // {
  2075. // LINE++;
  2076. // }
  2077. //
  2078. // i++;
  2079. // j++;
  2080. // UNBALANCEDCOMMENT = NO;
  2081. // }
  2082. //
  2083. // else if (UNBALANCEDCOMMENT == NO) //CASE 2 WHITESPACE DONE //CASE 3 NEWLINE DONE //CASE 4 // DONE //CASE 5 /**/ DONE
  2084. // {
  2085. // output[j] = array[i]; //SAVES /n THEN NEXT -- EXITS CHECKING AFTER ;
  2086. //
  2087. // if (array[i] == '\n')
  2088. // {
  2089. // LINE++;
  2090. // }
  2091. //
  2092. // i++;
  2093. // j++;
  2094. // }
  2095. // if (SYNTAXERROR == YES) //CASE 6 DONE
  2096. // {
  2097. // syntaxerror[k] = '\0';
  2098. // printf("Error: Syntax error. Text not in a comment on line %d. Code: %s\n", SYNTAXERRORONLINE, syntaxerror);
  2099. // syntaxerror[0] = '\0';
  2100. // k = 0;
  2101. // output[j] = array[i];
  2102. //
  2103. // if (array[i] == '\n')
  2104. // {
  2105. // LINE++;
  2106. // }
  2107. //
  2108. // i++;
  2109. // j++;
  2110. // SYNTAXERROR = NO;
  2111. // }
  2112. // } //; DONE
  2113. //
  2114. //
  2115. // else if (array[i] == '/') //3 CASES
  2116. // {
  2117. // UNBALANCEDCOMMENT = YES; //CASE 1 DONE
  2118. //
  2119. // COMMENTBEGANON = LINE;
  2120. //
  2121. // if (array[i + 1] == '/') //CASE 2
  2122. // {
  2123. // UNBALANCEDCOMMENT = NO;
  2124. //
  2125. // INACOMMENT = YES;
  2126. //
  2127. // while (array[i] != '\n')
  2128. // {
  2129. // i++;
  2130. // j++;
  2131. // output[j] = array[i];
  2132. // }
  2133. // INACOMMENT = NO; //CASE 2 DONE
  2134. // }
  2135. //
  2136. // else if (array[i + 1] == '*') //CASE 3
  2137. // {
  2138. // UNBALANCEDCOMMENT = YES;
  2139. //
  2140. // INACOMMENT = YES;
  2141. //
  2142. // COMMENTBEGANON = LINE;
  2143. //
  2144. // while (INACOMMENT == YES && array[i] != '\0')
  2145. // {
  2146. // if (array[i] == '\n')
  2147. // {
  2148. // LINE++; //LINE COUNTER
  2149. // }
  2150. // if (array[i] == '*')
  2151. // {
  2152. // i++;
  2153. // j++;
  2154. // output[j] == array[i];
  2155. // STAR = YES;
  2156. // }
  2157. // else if (array[i] == '/' && STAR == YES)
  2158. // {
  2159. // i++;
  2160. // j++;
  2161. // output[j] == array[i];
  2162. // INACOMMENT = NO;
  2163. // UNBALANCEDCOMMENT = NO;
  2164. // }
  2165. // else
  2166. // {
  2167. // i++;
  2168. // j++;
  2169. // output[j] == array[i];
  2170. // STAR = NO;
  2171. // }
  2172. // }
  2173. // if (INACOMMENT == NO && UNBALANCEDCOMMENT == NO && SYNTAXERROR == NO)
  2174. // {
  2175. // printf(" End of multi line comment that started on line %d. New line will be printed in case the next character is not a whitespace \n", COMMENTBEGANON); //CASE 3 DONE
  2176. // }
  2177. // }
  2178. // if (UNBALANCEDCOMMENT == YES) //CASE 1
  2179. // {
  2180. // printf("Error: Unbalanced comment on line %d. Missing / or *.\n", COMMENTBEGANON);
  2181. // output[j] = array[i];
  2182. //
  2183. // if (array[i] == '\n')
  2184. // {
  2185. // LINE++;
  2186. // }
  2187. //
  2188. // i++;
  2189. // j++;
  2190. // UNBALANCEDCOMMENT = NO;
  2191. // }
  2192. //
  2193. // else if (UNBALANCEDCOMMENT == NO) //CASE 2
  2194. // {
  2195. // output[j] = array[i]; //SAVES /n THEN NEXT
  2196. //
  2197. // if (array[i] == '\n')
  2198. // {
  2199. // LINE++;
  2200. // }
  2201. //
  2202. // i++;
  2203. // j++;
  2204. // }
  2205. // }
  2206. //
  2207. // else if (array[i] == '\'' && array[i - 1] != '\\')
  2208. // {
  2209. // INASINGLEQUOTE = YES;
  2210. // SINGLEQUOTEBEGANON = LINE;
  2211. // i++;
  2212. // j++;
  2213. //
  2214. // while (INASINGLEQUOTE == YES && array[i] != '\n') //could use one variable INAQUOTE
  2215. // {
  2216. // if (array[i] == '\'' && array[i - 1] != '\\')
  2217. // {
  2218. // INASINGLEQUOTE = NO;
  2219. // output[j] = array[i];
  2220. //
  2221. // i++;
  2222. // j++;
  2223. // }
  2224. // else
  2225. // {
  2226. // output[j] = array[i];
  2227. //
  2228. // i++;
  2229. // j++;
  2230. // }
  2231. // }
  2232. // if (INASINGLEQUOTE == YES)
  2233. // {
  2234. // printf("Error: Uneven single quote. The quote that started on line %d is missing a single quote \'.\n", SINGLEQUOTEBEGANON);
  2235. // INASINGLEQUOTE = NO;
  2236. // }
  2237. //
  2238. // }
  2239. //
  2240. // else if (array[i] == '"' && array[i - 1] != '\\')
  2241. // {
  2242. // INADOUBLEQUOTE = YES;
  2243. // DOUBLEQUOTEBEGANON = LINE; //could use one variable QUOTEBEGANON
  2244. // i++;
  2245. // j++;
  2246. // while (INADOUBLEQUOTE == YES && array[i] != '\n') //could use one variable INAQUOTE
  2247. // {
  2248. // if (array[i] == '"' && array[i - 1] != '\\')
  2249. // {
  2250. // INADOUBLEQUOTE = NO;
  2251. // output[j] = array[i];
  2252. //
  2253. // i++;
  2254. // j++;
  2255. // }
  2256. // else
  2257. // {
  2258. // output[j] = array[i];
  2259. //
  2260. // i++;
  2261. // j++;
  2262. // }
  2263. // }
  2264. // if (INADOUBLEQUOTE == YES)
  2265. // {
  2266. // printf("Error: Uneven double quote. The double quote that started on line %d is missing a single quote \".\n", DOUBLEQUOTEBEGANON);
  2267. // INADOUBLEQUOTE = NO;
  2268. // }
  2269. // }
  2270. //
  2271. // else if (array[i] == '[')
  2272. // {
  2273. // LeftBrackets++;
  2274. // EXTRABRACKETONLINE = LINE;
  2275. //
  2276. // i++;
  2277. // j++;
  2278. // if (LeftBrackets - RightBrackets > 1)
  2279. // {
  2280. // printf("Error: Uneven brackets. An extra [ was found on line %d.\n", EXTRABRACKETONLINE);
  2281. // }
  2282. // }
  2283. // else if (array[i] == ']')
  2284. // {
  2285. // RightBrackets++;
  2286. // EXTRABRACKETONLINE = LINE;
  2287. //
  2288. // i++;
  2289. // j++;
  2290. // if (RightBrackets - LeftBrackets > 0)
  2291. // {
  2292. // printf("Error: Uneven brackets. An extra ] was found on line %d.\n", EXTRABRACKETONLINE);
  2293. // }
  2294. // }
  2295. //
  2296. // else if (array[i] == '(')
  2297. // {
  2298. // LeftParanthesis++;
  2299. // EXTRAPARENTHESISONLINE = LINE;
  2300. //
  2301. // i++;
  2302. // j++;
  2303. // }
  2304. // else if (array[i] == ')')
  2305. // {
  2306. // RightParenthesis++;
  2307. // EXTRAPARENTHESISONLINE = LINE;
  2308. //
  2309. // i++;
  2310. // j++;
  2311. // if (RightParenthesis > LeftParanthesis)
  2312. // {
  2313. // printf("Error: Uneven Right Parenthesis. An extra ) was found on line %d.\n", EXTRAPARENTHESISONLINE);
  2314. // }
  2315. // }
  2316. //
  2317. // else if (array[i] == '{')
  2318. // {
  2319. // LeftBraces++;
  2320. // EXTRABRACESONLINE = LINE;
  2321. //
  2322. // i++;
  2323. // j++;
  2324. // }
  2325. // else if (array[i] == '}')
  2326. // {
  2327. // RightBraces++;
  2328. // EXTRABRACESONLINE = LINE;
  2329. //
  2330. // i++;
  2331. // j++;
  2332. // if (RightBraces > LeftBraces)
  2333. // {
  2334. // printf("Error: Uneven Right Braces. An extra } was found on line %d.\n", EXTRABRACESONLINE);
  2335. // }
  2336. // }
  2337. // else if (array[i] != '\0' && array[i] != EOF)
  2338. // {
  2339. // i++;
  2340. // j++;
  2341. // }
  2342. // else
  2343. // ;
  2344. // }
  2345. //
  2346. // if (LeftBraces > RightBraces)
  2347. // {
  2348. // printf("Error: Uneven Left Braces. An extra { was found on line %d.\n", EXTRABRACESONLINE);
  2349. // }
  2350. //
  2351. // output[j] = '\0'; //DONE
  2352. // printf("%s\n", output); //PRINT OUTPUT
  2353. //}
  2354. /*
  2355. error
  2356. error; error
  2357. error; / error
  2358. error; //noerror
  2359. error; /*noerror*/
  2360. //error;/*noerror
  2361. //*/
  2362. //error; /*error/
  2363. //error; /*error*8/
  2364. //error:
  2365. //*/
  2366. //#define MAXARRAYSIZE 20000
  2367. //main()
  2368. //{
  2369. // int c;
  2370. // char array[MAXARRAYSIZE];
  2371. // int i = 0;
  2372. // char output[MAXARRAYSIZE];
  2373. // int j = 0;
  2374. // char syntaxerror[MAXARRAYSIZE];
  2375. // int k = 0;
  2376. // int LeftBrackets = 0;
  2377. // int RightBrackets = 0;
  2378. // int EXTRABRACKETONLINE = 0;
  2379. // int RightParenthesis = 0;
  2380. // int LeftParanthesis = 0;
  2381. // int EXTRAPARENTHESISONLINE = 0;
  2382. // int RightBraces = 0;
  2383. // int LeftBraces = 0;
  2384. // int EXTRALEFTBRACEONLINE = 0;
  2385. // int EXTRARIGHTBRACEONLINE = 0;
  2386. // int STAR = NO;
  2387. // int UNBALANCEDCOMMENT = NO;
  2388. // int INACOMMENT = NO;
  2389. // int COMMENTDONE = NO;
  2390. // int COMMENTBEGANON = 0;
  2391. // int COMMENTENDEDON = 0;
  2392. // int LINE = 2362;
  2393. // int SYNTAXERROR = NO;
  2394. // int SYNTAXERRORONLINE = 0;
  2395. // int INASINGLEQUOTE = NO;
  2396. // int INADOUBLEQUOTE = NO;
  2397. // int SINGLEQUOTEBEGANON = 0;
  2398. // int DOUBLEQUOTEBEGANON = 0;
  2399. // int HEXSYNTAXERROR = NO;
  2400. // int HEXSYNTAXERRORBEGANON = 0;
  2401. // //octal (come back)
  2402. // while ((c = getchar()) != EOF)
  2403. // {
  2404. // array[i] = c;
  2405. // i++;
  2406. // }
  2407. // array[i] = '\0';
  2408. // i = 0;
  2409. // printf("\n");//appears after data collection. if this was placed at the beginning of the program after the declarations the newline would be printed before the data collection (the terminal would appear initiate with a newline.
  2410. // while (array[i] != '\0' && array[i] != EOF)
  2411. // {
  2412. //
  2413. // if (array[i] == '\n')
  2414. // {
  2415. // LINE++; //LINE COUNTER
  2416. // if (LeftParanthesis > RightParenthesis)
  2417. // {
  2418. // printf("Error: Uneven Left Parenthesis. An extra ( was found on line %d.\n", EXTRAPARENTHESISONLINE);
  2419. // }
  2420. // RightBrackets = 0;
  2421. // LeftBrackets = 0;
  2422. // RightParenthesis = 0;
  2423. // LeftParanthesis = 0;
  2424. // }
  2425. // output[j] = array[i]; //STORES EVERY CHARACTER FROM array
  2426. //
  2427. // if (array[i] == ';') //THIS CHECKS FOR COMMENTS AFTER ;
  2428. // {
  2429. // i++;
  2430. // j++;
  2431. //
  2432. // output[j] = array[i]; //CHECKS EITHER // OR /* OR / OR WHITE SPACE OR NEWLINE . SIX DIFFERENT CASES.
  2433. // if (LeftParanthesis > RightParenthesis)
  2434. // {
  2435. // printf("Error: Uneven Left Parenthesis. An extra ( was found on line %d. \n", EXTRAPARENTHESISONLINE);
  2436. // }
  2437. // RightBrackets = 0;
  2438. // LeftBrackets = 0;
  2439. //
  2440. // while (array[i] != '\n' && array[i] != '\0' && array[i] != EOF) //WHILE THE CHARACTER WE JUST SAVED IS NOT THE NEW LINE \n CHECK THE SIX CASES
  2441. // {
  2442. // if (INACOMMENT == NO && array[i] != '/' && array[i] != '*' && array[i] != ' ' && array[i] != '\t') //CASE 6
  2443. // {
  2444. // while (array[i] != '/' && array[i] != '\n' && array[i] != '\0')
  2445. // {
  2446. // output[j] = array[i];
  2447. // syntaxerror[k] = array[i];
  2448. // SYNTAXERRORONLINE = LINE;
  2449. // k++;
  2450. // i++;
  2451. // j++;
  2452. // }
  2453. // syntaxerror[k] = ' ';
  2454. // k++;
  2455. // SYNTAXERROR = YES; //CASE 6 DONE
  2456. // }
  2457. //
  2458. // else if (array[i] == '/') //CASE 1 2 3 4 5
  2459. // {
  2460. // output[j] = array[i];
  2461. //
  2462. // UNBALANCEDCOMMENT = YES; //CASE 1 DONE
  2463. //
  2464. // COMMENTBEGANON = LINE;
  2465. //
  2466. // if (array[i + 1] == '/') //CASE 4
  2467. // {
  2468. // UNBALANCEDCOMMENT = NO;
  2469. // INACOMMENT = YES;
  2470. // while (array[i] != '\n')
  2471. // {
  2472. // i++;
  2473. // j++;
  2474. // output[j] = array[i]; //CASE 4 DONE
  2475. // }
  2476. // INACOMMENT = NO;
  2477. // }
  2478. //
  2479. // else if (array[i + 1] == '*') //CASE 5
  2480. // {
  2481. // UNBALANCEDCOMMENT = YES;
  2482. // INACOMMENT = YES;
  2483. // COMMENTBEGANON = LINE;
  2484. // i++;
  2485. // j++;
  2486. // output[j] = array[i];
  2487. // i++;
  2488. // j++;
  2489. // while (INACOMMENT == YES && array[i] != '\0')
  2490. // {
  2491. // if (array[i] == '\n')
  2492. // {
  2493. // LINE++; //LINE COUNTER
  2494. // output[j] = array[i];
  2495. // i++;
  2496. // j++;
  2497. // if (LeftParanthesis > RightParenthesis)
  2498. // {
  2499. // printf("Error: Uneven Left Parenthesis. An extra ( was found on line %d.\n", EXTRAPARENTHESISONLINE);
  2500. // }
  2501. // RightBrackets = 0;
  2502. // LeftBrackets = 0;
  2503. // RightParenthesis = 0;
  2504. // LeftParanthesis = 0;
  2505. // }
  2506. // else if (array[i] == '*')
  2507. // {
  2508. // output[j] = array[i];
  2509. // i++;
  2510. // j++;
  2511. // STAR = YES;
  2512. // }
  2513. // else if (array[i] == '/' && STAR == YES)
  2514. // {
  2515. // output[j] = array[i];
  2516. // i++;
  2517. // j++;
  2518. // INACOMMENT = NO;
  2519. // UNBALANCEDCOMMENT = NO;
  2520. // COMMENTENDEDON = LINE;
  2521. // STAR = NO;
  2522. // }
  2523. // else
  2524. // {
  2525. // output[j] = array[i];
  2526. // i++;
  2527. // j++;
  2528. // STAR = NO;
  2529. // }
  2530. // }
  2531. // if (INACOMMENT == NO && UNBALANCEDCOMMENT == NO)
  2532. // {
  2533. // printf("Multi-line comment started on line %d and ended on %d.\n", COMMENTBEGANON, COMMENTENDEDON); //CASE 5 DONE
  2534. // }
  2535. // }
  2536. //
  2537. // else
  2538. // {
  2539. // syntaxerror[k] = array[i];
  2540. // output[j] = array[i];
  2541. // i++;
  2542. // j++;
  2543. // k++;
  2544. //
  2545. // while (array[i] != '\n' && array[i] != '/' && array[i] != '\0' && array[i] != EOF)
  2546. // {
  2547. // syntaxerror[k] = array[i]; // / a b
  2548. // output[j] = array[i];
  2549. // i++;
  2550. // j++;
  2551. // k++;
  2552. // SYNTAXERRORONLINE = LINE;
  2553. // }
  2554. // SYNTAXERROR = YES;
  2555. // }
  2556. // }
  2557. // else
  2558. // {
  2559. // ; //NEXT CHARACTER HANDLED IN THE UNBALANCED COMMENT CODE BLOCK
  2560. // /*i++;
  2561. // j++;*/
  2562. // }
  2563. // }
  2564. //
  2565. // if (UNBALANCEDCOMMENT == YES) //CASE 1
  2566. // {
  2567. // printf("Error: Unbalanced comment on line %d. Missing / or *.\n", COMMENTBEGANON);
  2568. // output[j] = array[i];
  2569. //
  2570. // if (array[i] == '\0')
  2571. // {
  2572. // printf("\n%s\n", output);
  2573. // }
  2574. // if (array[i] == '\n')
  2575. // {
  2576. // LINE++;
  2577. // if (LeftParanthesis > RightParenthesis)
  2578. // {
  2579. // printf("Error: Uneven Left Parenthesis. An extra ( was found on line %d.\n", EXTRAPARENTHESISONLINE);
  2580. // }
  2581. // RightBrackets = 0;
  2582. // LeftBrackets = 0;
  2583. // RightParenthesis = 0;
  2584. // LeftParanthesis = 0;
  2585. // }
  2586. //
  2587. // i++;
  2588. // j++;
  2589. // UNBALANCEDCOMMENT = NO;
  2590. // }
  2591. //
  2592. // else if (UNBALANCEDCOMMENT == NO) //CASE 2 WHITESPACE DONE //CASE 3 NEWLINE DONE //CASE 4 // DONE //CASE 5 /**/ DONE
  2593. // {
  2594. // output[j] = array[i]; //SAVES /n THEN NEXT -- EXITS CHECKING AFTER ;
  2595. //
  2596. // if (array[i] == '\n')
  2597. // {
  2598. // LINE++;
  2599. // if (LeftParanthesis > RightParenthesis)
  2600. // {
  2601. // printf("Error: Uneven Left Parenthesis. An extra ( was found on line %d.\n", EXTRAPARENTHESISONLINE);
  2602. // }
  2603. // RightBrackets = 0;
  2604. // LeftBrackets = 0;
  2605. // RightParenthesis = 0;
  2606. // LeftParanthesis = 0;
  2607. // }
  2608. //
  2609. // i++;
  2610. // j++;
  2611. // }
  2612. // if (SYNTAXERROR == YES) //CASE 6 DONE
  2613. // {
  2614. // syntaxerror[k] = '\0';
  2615. // printf("Error: Syntax error. Text not in a comment on line %d. Code: %s\n", SYNTAXERRORONLINE, syntaxerror);
  2616. // syntaxerror[0] = '\0';
  2617. // k = 0;
  2618. // output[j] = array[i];
  2619. //
  2620. // if (array[i] == '\n')
  2621. // {
  2622. // if (LeftParanthesis > RightParenthesis)
  2623. // {
  2624. // printf("Error: Uneven Left Parenthesis. An extra ( was found on line %d.\n", EXTRAPARENTHESISONLINE);
  2625. // }
  2626. // LINE++;
  2627. // RightBrackets = 0;
  2628. // LeftBrackets = 0;
  2629. // RightParenthesis = 0;
  2630. // LeftParanthesis = 0;
  2631. // }
  2632. //
  2633. // i++;
  2634. // j++;
  2635. // SYNTAXERROR = NO;
  2636. // }
  2637. // } //; DONE
  2638. // else if (array[i] == '/') //3 CASES
  2639. // {
  2640. // output[j] = array[i];
  2641. //
  2642. // UNBALANCEDCOMMENT = YES; //CASE 1 DONE
  2643. //
  2644. // COMMENTBEGANON = LINE;
  2645. //
  2646. // if (array[i + 1] == '/') //CASE 4
  2647. // {
  2648. // UNBALANCEDCOMMENT = NO;
  2649. // INACOMMENT = YES;
  2650. // while (array[i] != '\n')
  2651. // {
  2652. // i++;
  2653. // j++;
  2654. // output[j] = array[i]; //CASE 4 DONE
  2655. // }
  2656. // INACOMMENT = NO;
  2657. // }
  2658. //
  2659. // else if (array[i + 1] == '*') //CASE 3
  2660. // {
  2661. // UNBALANCEDCOMMENT = YES;
  2662. //
  2663. // INACOMMENT = YES;
  2664. //
  2665. // COMMENTBEGANON = LINE;
  2666. // i++;
  2667. // j++;
  2668. // output[j] = array[i];
  2669. // i++;
  2670. // j++;
  2671. // while (INACOMMENT == YES && array[i] != '\0')
  2672. // {
  2673. // if (array[i] == '\n')
  2674. // {
  2675. // LINE++; //LINE COUNTER
  2676. // output[j] = array[i];
  2677. // i++;
  2678. // j++;
  2679. // if (LeftParanthesis > RightParenthesis)
  2680. // {
  2681. // printf("Error: Uneven Left Parenthesis. An extra ( was found on line %d.\n", EXTRAPARENTHESISONLINE);
  2682. // }
  2683. // RightBrackets = 0;
  2684. // LeftBrackets = 0;
  2685. // RightParenthesis = 0;
  2686. // LeftParanthesis = 0;
  2687. // }
  2688. // else if (array[i] == '*')
  2689. // {
  2690. // output[j] = array[i];
  2691. // i++;
  2692. // j++;
  2693. // STAR = YES;
  2694. // }
  2695. // else if (array[i] == '/' && STAR == YES)
  2696. // {
  2697. // output[j] = array[i];
  2698. // i++;
  2699. // j++;
  2700. // INACOMMENT = NO;
  2701. // UNBALANCEDCOMMENT = NO;
  2702. // COMMENTENDEDON = LINE;
  2703. // STAR = NO;
  2704. // }
  2705. // else
  2706. // {
  2707. // output[j] = array[i];
  2708. // i++;
  2709. // j++;
  2710. // STAR = NO;
  2711. // }
  2712. // }
  2713. // if (INACOMMENT == NO && UNBALANCEDCOMMENT == NO)
  2714. // {
  2715. // printf("Multi-line comment started on line %d and ended on %d.\n", COMMENTBEGANON, COMMENTENDEDON);
  2716. // }
  2717. // }
  2718. // else
  2719. // ; //NEXT CHARACTER HANDLED IN THE UNBALANCED CODE BLOCK
  2720. // if (UNBALANCEDCOMMENT == YES) //CASE 1
  2721. // {
  2722. // printf("Error: Unbalanced comment on line %d. Missing / or *.\n", COMMENTBEGANON);
  2723. // output[j] = array[i];
  2724. //
  2725. // if (array[i] == '\n')
  2726. // {
  2727. // LINE++;
  2728. // if (LeftParanthesis > RightParenthesis)
  2729. // {
  2730. // printf("Error: Uneven Left Parenthesis. An extra ( was found on line %d.\n", EXTRAPARENTHESISONLINE);
  2731. // }
  2732. // RightBrackets = 0;
  2733. // LeftBrackets = 0;
  2734. // RightParenthesis = 0;
  2735. // LeftParanthesis = 0;
  2736. // }
  2737. //
  2738. // i++;
  2739. // j++;
  2740. // UNBALANCEDCOMMENT = NO;
  2741. // }
  2742. //
  2743. // else if (UNBALANCEDCOMMENT == NO) //CASE 2
  2744. // {
  2745. // output[j] = array[i]; //SAVES /n THEN NEXT
  2746. //
  2747. // if (array[i] == '\n')
  2748. // {
  2749. // LINE++;
  2750. // if (LeftParanthesis > RightParenthesis)
  2751. // {
  2752. // printf("Error: Uneven Left Parenthesis. An extra ( was found on line %d.\n", EXTRAPARENTHESISONLINE);
  2753. // }
  2754. // RightBrackets = 0;
  2755. // LeftBrackets = 0;
  2756. // RightParenthesis = 0;
  2757. // LeftParanthesis = 0;
  2758. // }
  2759. //
  2760. // i++;
  2761. // j++;
  2762. // }
  2763. // }
  2764. //
  2765. // else if (array[i] == '\'' && array[i - 1] != '\\') //wow '\\' is reading \' wow SO THE CODE READS ' and before that the last two characters are \\. cases like \"' work as expected before this fix. LATEST DEBUG 5:02 PM 11/20/2019
  2766. // {
  2767. // INASINGLEQUOTE = YES;
  2768. // SINGLEQUOTEBEGANON = LINE;
  2769. // i++;
  2770. // j++;
  2771. //
  2772. // while (INASINGLEQUOTE == YES && array[i] != '\n') //if hex number must be 0-9 A-F until a space is read.
  2773. // {
  2774. // if (array[i] == '\'' && array[i - 1] != '\\') // && array[i-2] == "\""
  2775. // {
  2776. // INASINGLEQUOTE = NO;
  2777. // output[j] = array[i];
  2778. //
  2779. // i++;
  2780. // j++;
  2781. // }
  2782. // else if (array[i] == '\'' && array[i - 1] == '\\' && array[i - 2] == '\\')
  2783. // {
  2784. // INASINGLEQUOTE = NO;
  2785. // output[j] = array[i];
  2786. //
  2787. // i++;
  2788. // j++;
  2789. // }
  2790. // else if (array[i] == 'x' && array[i - 1] == '\\' && array[i-2] != '\\')
  2791. // {
  2792. // output[j] = array[i];
  2793. //
  2794. // i++;
  2795. // j++;
  2796. // while (array[i] != ' ' && array[i] != '\'' && array[i] != '\n')
  2797. // {
  2798. // if (array[i] != '0' && array[i] != '1' && array[i] != '2' && array[i] != '3' && array[i] != '4' && array[i] != '5' && array[i] != '6' && array[i] != '7' && array[i] != '8' && array[i] != '9' && array[i] != 'A' && array[i] != 'B' && array[i] != 'C' && array[i] != 'D' && array[i] != 'E' && array[i] != 'F')
  2799. // {
  2800. // HEXSYNTAXERROR = YES;
  2801. // HEXSYNTAXERRORBEGANON = LINE;
  2802. // }
  2803. // output[j] = array[i];
  2804. //
  2805. // i++;
  2806. // j++;
  2807. // }
  2808. // }
  2809. // else
  2810. // {
  2811. //
  2812. // output[j] = array[i];
  2813. //
  2814. // i++;
  2815. // j++;
  2816. // }
  2817. // }
  2818. // if (INASINGLEQUOTE == YES)
  2819. // {
  2820. // printf("Error: Uneven single quote. The single quote that started on line %d is missing a single quote \'.\n", SINGLEQUOTEBEGANON);
  2821. // INASINGLEQUOTE = NO;
  2822. // }
  2823. // if (HEXSYNTAXERROR == YES)
  2824. // {
  2825. // printf("Error: Syntax error. The hexidecimal number on line %d is not acceptable.\n", HEXSYNTAXERRORBEGANON);
  2826. // HEXSYNTAXERROR = NO;
  2827. // }
  2828. // }
  2829. //
  2830. // else if (array[i] == '"' && array[i - 1] != '\\')
  2831. // {
  2832. // INADOUBLEQUOTE = YES;
  2833. // DOUBLEQUOTEBEGANON = LINE; //could use one variable QUOTEBEGANON
  2834. // i++;
  2835. // j++;
  2836. // while (INADOUBLEQUOTE == YES && array[i] != '\n') //could use one variable INAQUOTE
  2837. // {
  2838. // if (array[i] == '"' && array[i - 1] != '\\')
  2839. // {
  2840. // INADOUBLEQUOTE = NO;
  2841. // output[j] = array[i];
  2842. //
  2843. // i++;
  2844. // j++;
  2845. // }
  2846. // else if (array[i] == '"' && array[i - 1] == '\\' && array[i - 2] == '\\')
  2847. // {
  2848. // INADOUBLEQUOTE = NO;
  2849. // output[j] = array[i];
  2850. //
  2851. // i++;
  2852. // j++;
  2853. // }
  2854. // else if (array[i] == 'x' && array[i - 1] == '\\' && array[i - 2] != '\\')
  2855. // {
  2856. // output[j] = array[i];
  2857. //
  2858. // i++;
  2859. // j++;
  2860. // while (array[i] != ' ' && array[i] != '\'' && array[i] != '\n')
  2861. // {
  2862. // if (array[i] != '0' && array[i] != '1' && array[i] != '2' && array[i] != '3' && array[i] != '4' && array[i] != '5' && array[i] != '6' && array[i] != '7' && array[i] != '8' && array[i] != '9' && array[i] != 'A' && array[i] != 'B' && array[i] != 'C' && array[i] != 'D' && array[i] != 'E' && array[i] != 'F')
  2863. // {
  2864. // HEXSYNTAXERROR = YES;
  2865. // HEXSYNTAXERRORBEGANON = LINE;
  2866. // }
  2867. // output[j] = array[i];
  2868. //
  2869. // i++;
  2870. // j++;
  2871. // }
  2872. // }
  2873. // else
  2874. // {
  2875. // output[j] = array[i];
  2876. //
  2877. // i++;
  2878. // j++;
  2879. // }
  2880. // }
  2881. // if (INADOUBLEQUOTE == YES)
  2882. // {
  2883. // printf("Error: Uneven double quote. The double quote that started on line %d is missing a double quote \".\n", DOUBLEQUOTEBEGANON);
  2884. // INADOUBLEQUOTE = NO;
  2885. // }
  2886. // if (HEXSYNTAXERROR == YES)
  2887. // {
  2888. // printf("Error: Syntax error. The hexidecimal number on line %d is not acceptable.\n", HEXSYNTAXERRORBEGANON);
  2889. // HEXSYNTAXERROR = NO;
  2890. // }
  2891. // }
  2892. //
  2893. // else if (array[i] == '[')
  2894. // {
  2895. // LeftBrackets++;
  2896. // EXTRABRACKETONLINE = LINE;
  2897. //
  2898. // i++;
  2899. // j++;
  2900. // if (LeftBrackets - RightBrackets > 1)
  2901. // {
  2902. // printf("Error: Uneven brackets. An extra [ was found on line %d.\n", EXTRABRACKETONLINE);
  2903. // }
  2904. // }
  2905. // else if (array[i] == ']')
  2906. // {
  2907. // RightBrackets++;
  2908. // EXTRABRACKETONLINE = LINE;
  2909. //
  2910. // i++;
  2911. // j++;
  2912. // if (RightBrackets - LeftBrackets > 0)
  2913. // {
  2914. // printf("Error: Uneven brackets. An extra ] was found on line %d.\n", EXTRABRACKETONLINE);
  2915. // }
  2916. // }
  2917. //
  2918. // else if (array[i] == '(')
  2919. // {
  2920. // LeftParanthesis++;
  2921. // EXTRAPARENTHESISONLINE = LINE;
  2922. //
  2923. // i++;
  2924. // j++;
  2925. // }
  2926. // else if (array[i] == ')')
  2927. // {
  2928. // RightParenthesis++;
  2929. // EXTRAPARENTHESISONLINE = LINE;
  2930. //
  2931. // i++;
  2932. // j++;
  2933. // if (RightParenthesis > LeftParanthesis)
  2934. // {
  2935. // printf("Error: Uneven Right Parenthesis. An extra ) was found on line %d.\n", EXTRAPARENTHESISONLINE);
  2936. // }
  2937. // }
  2938. //
  2939. // else if (array[i] == '{')
  2940. // {
  2941. // LeftBraces++;
  2942. // EXTRALEFTBRACEONLINE = LINE;
  2943. //
  2944. // i++;
  2945. // j++;
  2946. // }
  2947. // else if (array[i] == '}')
  2948. // {
  2949. // RightBraces++;
  2950. // EXTRARIGHTBRACEONLINE = LINE;
  2951. //
  2952. // i++;
  2953. // j++;
  2954. // if (RightBraces > LeftBraces)
  2955. // {
  2956. // printf("Error: Uneven Right Braces. An extra } was found on line %d.\n", EXTRARIGHTBRACEONLINE);
  2957. // }
  2958. // }
  2959. // else if (array[i] != '\0' && array[i] != EOF)
  2960. // {
  2961. // i++;
  2962. // j++;
  2963. // }
  2964. // else
  2965. // ;
  2966. // }
  2967. //
  2968. // if (LeftBraces > RightBraces)
  2969. // {
  2970. // printf("Error: Uneven Left Braces. An extra { was found on line %d.\n", EXTRALEFTBRACEONLINE);
  2971. // }
  2972. //
  2973. // output[j] = '\0'; //DONE
  2974. // printf("\n%s\n", output); //PRINT OUTPUT
  2975. //}
  2976. //
  2977. //void checkCommentsAfterSemicolon(char array[]); //line 0
  2978. //void checkComments(char array[]);
  2979. //void checkSingleQuotes(char array[]);
  2980. //void checkDoubleQuotes(char array[]);
  2981. //void checkHexidecimalEscapeSequences(char array[]);
  2982. //void checkBrackets(char array[]);
  2983. //void checkParenthesis(char array[]);
  2984. //void checkBraces(char array[]);
  2985. //
  2986. //#define MAXARRAYSIZE 50000
  2987. //main()
  2988. //{
  2989. // int c;
  2990. // char array[MAXARRAYSIZE];
  2991. // int i = 0;
  2992. // //octal (come back)
  2993. //
  2994. // while ((c = getchar()) != EOF)
  2995. // {
  2996. // array[i] = c;
  2997. // i++;
  2998. // }
  2999. // array[i] = '\0';
  3000. //
  3001. // printf("\n");
  3002. // //line 0
  3003. // checkCommentsAfterSemicolon(array);
  3004. //
  3005. // checkComments(array);
  3006. //
  3007. // checkSingleQuotes(array);
  3008. //
  3009. // checkDoubleQuotes(array);
  3010. //
  3011. // checkHexidecimalEscapeSequences(array); //line 34
  3012. //
  3013. // checkBrackets(array);
  3014. //
  3015. // checkParenthesis(array);
  3016. //
  3017. // printf("\ndone\n");
  3018. //}
  3019. //
  3020. //void checkCommentsAfterSemicolon(char array[])
  3021. //{
  3022. // int i = 0;
  3023. // char syntaxerror[MAXARRAYSIZE];
  3024. // int k = 0;
  3025. // int STAR = NO;
  3026. // int UNBALANCEDCOMMENT = NO;
  3027. // int INACOMMENT = NO;
  3028. // int COMMENTBEGANON = 0;
  3029. // int COMMENTENDEDON = 0;
  3030. // int LINE = 0;
  3031. // int SYNTAXERROR = NO;
  3032. // int SYNTAXERRORONLINE = 0;
  3033. // int INASINGLEQUOTE = NO;
  3034. // int INADOUBLEQUOTE = NO;
  3035. //
  3036. // while (array[i] != '\0' && array[i] != EOF)
  3037. // {
  3038. // if (array[i] == ';') //line 34
  3039. // {
  3040. // i++;
  3041. // while (array[i] != '\n' && array[i] != '\0' && array[i] != EOF) //WHILE THE CHARACTER WE JUST SAVED IS NOT THE NEW LINE \n CHECK THE SIX CASES
  3042. // {
  3043. // if (INACOMMENT == NO && array[i] != '/' && array[i] != ' ' && array[i] != '\t') //CASE 6
  3044. // {
  3045. // while (array[i] != '/' && array[i] != '\n' && array[i] != '\0' && array[i] != EOF)
  3046. // {
  3047. // syntaxerror[k] = array[i];
  3048. // SYNTAXERRORONLINE = LINE;
  3049. // k++;
  3050. // i++;
  3051. // }
  3052. // syntaxerror[k] = ' ';
  3053. // k++;
  3054. // SYNTAXERROR = YES; //CASE 6 DONE
  3055. // }
  3056. //
  3057. // else if (array[i] == '/') //CASE 1 2 3 4 5
  3058. // {
  3059. // UNBALANCEDCOMMENT = YES; //CASE 1 DONE
  3060. //
  3061. // COMMENTBEGANON = LINE;
  3062. //
  3063. // if (array[i + 1] == '/') //CASE 4
  3064. // {
  3065. // UNBALANCEDCOMMENT = NO;
  3066. // INACOMMENT = YES;
  3067. // while (array[i] != '\n' && array[i] != '\0' && array[i] != EOF)
  3068. // {
  3069. // i++;
  3070. // }
  3071. // INACOMMENT = NO;
  3072. // }
  3073. //
  3074. // else if (array[i + 1] == '*') //CASE 5
  3075. // {
  3076. // UNBALANCEDCOMMENT = YES;
  3077. // INACOMMENT = YES;
  3078. // COMMENTBEGANON = LINE;
  3079. // i++;
  3080. // i++;
  3081. // while (INACOMMENT == YES && array[i] != '\0' && array[i] != EOF)
  3082. // {
  3083. // if (array[i] == '\n')
  3084. // {
  3085. // LINE++; //LINE COUNTER
  3086. // i++;
  3087. // }
  3088. // else if (array[i] == '*')
  3089. // {
  3090. // i++;
  3091. // STAR = YES;
  3092. // }
  3093. // else if (array[i] == '/' && STAR == YES)
  3094. // {
  3095. // i++;
  3096. // INACOMMENT = NO;
  3097. // UNBALANCEDCOMMENT = NO;
  3098. // STAR = NO;
  3099. // }
  3100. // else
  3101. // {
  3102. // i++;
  3103. // STAR = NO;
  3104. // }
  3105. // }
  3106. // if (INACOMMENT == NO && UNBALANCEDCOMMENT == NO)
  3107. // {
  3108. // printf("Multi-line comment started on line %d and ended on %d.\n", COMMENTBEGANON, COMMENTENDEDON); //CASE 5 DONE
  3109. // /*test
  3110. // */
  3111. // }
  3112. // }
  3113. //
  3114. // else
  3115. // {
  3116. // printf("5\n");
  3117. // syntaxerror[k] = array[i];
  3118. // i++;
  3119. // k++;
  3120. //
  3121. // while (array[i] != '\n' && array[i] != '/' && array[i] != '\0' && array[i] != EOF)
  3122. // {
  3123. // syntaxerror[k] = array[i]; // / a b
  3124. // i++;
  3125. // k++;
  3126. // SYNTAXERRORONLINE = LINE;
  3127. // }
  3128. // SYNTAXERROR = YES;
  3129. // }
  3130. // }
  3131. // else
  3132. // i++;
  3133. // }
  3134. //
  3135. // if (UNBALANCEDCOMMENT == YES) //CASE 1
  3136. // {
  3137. // printf("Error: Unbalanced comment on line %d. Missing / or *.\n", COMMENTBEGANON);
  3138. //
  3139. // if (array[i] == '\0')
  3140. // {
  3141. // //printf("\n%s\n", output);
  3142. // printf("null\n");
  3143. // }
  3144. //
  3145. // if (array[i] == EOF)
  3146. // {
  3147. // printf("EOF\n");
  3148. // }
  3149. //
  3150. // if (array[i] == '\n')
  3151. // {
  3152. // LINE++;
  3153. // }
  3154. //
  3155. // i++;
  3156. // UNBALANCEDCOMMENT = NO;
  3157. // }
  3158. //
  3159. // else if (UNBALANCEDCOMMENT == NO) //CASE 2 WHITESPACE DONE //CASE 3 NEWLINE DONE //CASE 4 // DONE //CASE 5 /**/ DONE
  3160. // {
  3161. // if (array[i] == '\n')
  3162. // {
  3163. // LINE++;
  3164. // }
  3165. // i++;
  3166. // }
  3167. // if (SYNTAXERROR == YES) //CASE 6 DONE
  3168. // {
  3169. // syntaxerror[k] = '\0';
  3170. // printf("Error: Syntax error. Text not in a comment on line %d. Code: %s\n", SYNTAXERRORONLINE, syntaxerror);
  3171. // syntaxerror[0] = '\0';
  3172. // k = 0;
  3173. // if (array[i] == '\n')
  3174. // {
  3175. // LINE++;
  3176. // }
  3177. //
  3178. // i++;
  3179. // SYNTAXERROR = NO;
  3180. // }
  3181. // }
  3182. // else if (array[i] == '/') //3 CASES
  3183. // {
  3184. // UNBALANCEDCOMMENT = YES; //CASE 1 DONE
  3185. //
  3186. // COMMENTBEGANON = LINE;
  3187. //
  3188. // if (array[i + 1] == '/') //CASE 4
  3189. // {
  3190. // UNBALANCEDCOMMENT = NO;
  3191. // INACOMMENT = YES;
  3192. // while (array[i] != '\n' && array[i] != '\0' && array[i] != EOF)
  3193. // {
  3194. // i++;
  3195. // }
  3196. // INACOMMENT = NO;
  3197. // }
  3198. //
  3199. // else if (array[i + 1] == '*') //CASE 3
  3200. // {
  3201. // UNBALANCEDCOMMENT = YES;
  3202. //
  3203. // INACOMMENT = YES;
  3204. //
  3205. // COMMENTBEGANON = LINE;
  3206. // i++;
  3207. // i++;
  3208. // while (INACOMMENT == YES && array[i] != '\0' && array[i] != EOF)
  3209. // {
  3210. // if (array[i] == '\n')
  3211. // {
  3212. // LINE++; //LINE COUNTER
  3213. // i++;
  3214. // }
  3215. // else if (array[i] == '*')
  3216. // {
  3217. // i++;
  3218. // STAR = YES;
  3219. // }
  3220. // else if (array[i] == '/' && STAR == YES)
  3221. // {
  3222. // i++;
  3223. // INACOMMENT = NO;
  3224. // UNBALANCEDCOMMENT = NO;
  3225. // COMMENTENDEDON = LINE;
  3226. // STAR = NO;
  3227. // }
  3228. // else
  3229. // {
  3230. // i++;
  3231. // STAR = NO;
  3232. // }
  3233. // }
  3234. // if (INACOMMENT == NO && UNBALANCEDCOMMENT == NO)
  3235. // {
  3236. // printf("Multi-line comment started on line %d and ended on %d.\n", COMMENTBEGANON, COMMENTENDEDON); //style
  3237. // }
  3238. // }
  3239. // else
  3240. // ; //NEXT CHARACTER (' ') IS HANDLED IN THE UNBALANCED COMMENT CODE BLOCK
  3241. // if (UNBALANCEDCOMMENT == YES) //CASE 1
  3242. // {
  3243. // printf("Error: Unbalanced comment on line %d. Missing / or *.\n", COMMENTBEGANON);
  3244. //
  3245. // if (array[i] == '\n')
  3246. // {
  3247. // LINE++;
  3248. // }
  3249. //
  3250. // i++;
  3251. // UNBALANCEDCOMMENT = NO;
  3252. // }
  3253. //
  3254. // else if (UNBALANCEDCOMMENT == NO) //CASE 2
  3255. // {
  3256. //
  3257. // if (array[i] == '\n')
  3258. // {
  3259. // LINE++;
  3260. // }
  3261. // i++;
  3262. // }
  3263. // }
  3264. // else if (array[i] == '\'' && array[i - 1] != '\\') //wow '\\' is reading \' wow SO THE CODE READS ' and before that the last two characters are \\. cases like \"' work as expected before this fix. LATEST DEBUG 5:02 PM 11/20/2019
  3265. // {
  3266. // INASINGLEQUOTE = YES;
  3267. // i++;
  3268. //
  3269. // while (INASINGLEQUOTE == YES && array[i] != '\n' && array[i] != '\0' && array[i] != EOF) //if hex number must be 0-9 A-F until a space is read.
  3270. // {
  3271. // if (array[i] == '\'' && array[i - 1] != '\\') // && array[i-2] == "\""
  3272. // {
  3273. // INASINGLEQUOTE = NO;
  3274. // i++;
  3275. // }
  3276. // else if (array[i] == '\'' && array[i - 1] == '\\' && array[i - 2] == '\\')
  3277. // {
  3278. // INASINGLEQUOTE = NO;
  3279. // i++;
  3280. // }
  3281. // else
  3282. // {
  3283. // i++;
  3284. // }
  3285. // }
  3286. // if (INASINGLEQUOTE == YES)
  3287. // {
  3288. // INASINGLEQUOTE = NO;
  3289. // }
  3290. // }
  3291. // else if (array[i] == '"' && array[i - 1] != '\\')
  3292. // {
  3293. // INADOUBLEQUOTE = YES;
  3294. // i++;
  3295. // while (INADOUBLEQUOTE == YES && array[i] != '\n' && array[i] != '\0' && array[i] != EOF) //could use one variable INAQUOTE
  3296. // {
  3297. // if (array[i] == '"' && array[i - 1] != '\\')
  3298. // {
  3299. // INADOUBLEQUOTE = NO;
  3300. // i++;
  3301. // }
  3302. // else if (array[i] == '"' && array[i - 1] == '\\' && array[i - 2] == '\\')
  3303. // {
  3304. // INADOUBLEQUOTE = NO;
  3305. // i++;
  3306. // }
  3307. // else
  3308. // {
  3309. // i++;
  3310. // }
  3311. // }
  3312. // if (INADOUBLEQUOTE == YES)
  3313. // {
  3314. // INADOUBLEQUOTE = NO;
  3315. // }
  3316. // }
  3317. // else
  3318. // {
  3319. // if (array[i] == '\n')
  3320. // {
  3321. // LINE++;
  3322. // }
  3323. // i++;
  3324. // }
  3325. // }
  3326. //}
  3327. //
  3328. //void checkComments(char array[])
  3329. //{
  3330. // int i = 0;
  3331. // int STAR = NO;
  3332. // int UNBALANCEDCOMMENT = NO;
  3333. // int INACOMMENT = NO;
  3334. // int COMMENTBEGANON = 0;
  3335. // int COMMENTENDEDON = 0;
  3336. // int LINE = 0;
  3337. // int INASINGLEQUOTE = NO;
  3338. // int INADOUBLEQUOTE = NO;
  3339. //
  3340. // while (array[i] != '\0' && array[i] != EOF)
  3341. // {
  3342. // if (array[i] == '/') //3 CASES
  3343. // {
  3344. // UNBALANCEDCOMMENT = YES; //CASE 1 DONE
  3345. //
  3346. // COMMENTBEGANON = LINE;
  3347. //
  3348. // if (array[i + 1] == '/') //CASE 4
  3349. // {
  3350. // UNBALANCEDCOMMENT = NO;
  3351. // INACOMMENT = YES;
  3352. // while (array[i] != '\n' && array[i] != '\0' && array[i] != EOF)
  3353. // {
  3354. // i++;
  3355. // }
  3356. // INACOMMENT = NO;
  3357. // }
  3358. //
  3359. // else if (array[i + 1] == '*') //CASE 3
  3360. // {
  3361. // UNBALANCEDCOMMENT = YES;
  3362. //
  3363. // INACOMMENT = YES;
  3364. //
  3365. // COMMENTBEGANON = LINE;
  3366. // i++;
  3367. // i++;
  3368. // while (INACOMMENT == YES && array[i] != '\0' && array[i] != EOF)
  3369. // {
  3370. // if (array[i] == '\n')
  3371. // {
  3372. // LINE++; //LINE COUNTER
  3373. // i++;
  3374. // }
  3375. // else if (array[i] == '*')
  3376. // {
  3377. // i++;
  3378. // STAR = YES;
  3379. // }
  3380. // else if (array[i] == '/' && STAR == YES)
  3381. // {
  3382. // i++;
  3383. // INACOMMENT = NO;
  3384. // UNBALANCEDCOMMENT = NO;
  3385. // COMMENTENDEDON = LINE;
  3386. // STAR = NO;
  3387. // }
  3388. // else
  3389. // {
  3390. // i++;
  3391. // STAR = NO;
  3392. // }
  3393. // }
  3394. // if (INACOMMENT == NO && UNBALANCEDCOMMENT == NO)
  3395. // {
  3396. // printf("Multi-line comment started on line %d and ended on %d.\n", COMMENTBEGANON, COMMENTENDEDON); //style
  3397. // }
  3398. // }
  3399. // else
  3400. // ; //NEXT CHARACTER (' ') IS HANDLED IN THE UNBALANCED COMMENT CODE BLOCK
  3401. // if (UNBALANCEDCOMMENT == YES) //CASE 1
  3402. // {
  3403. // printf("Error: Unbalanced comment on line %d. Missing / or *.\n", COMMENTBEGANON);
  3404. //
  3405. // if (array[i] == '\n')
  3406. // {
  3407. // LINE++;
  3408. // }
  3409. //
  3410. // i++;
  3411. // UNBALANCEDCOMMENT = NO;
  3412. // }
  3413. //
  3414. // else if (UNBALANCEDCOMMENT == NO) //CASE 2
  3415. // {
  3416. //
  3417. // if (array[i] == '\n')
  3418. // {
  3419. // LINE++;
  3420. // }
  3421. // i++;
  3422. // }
  3423. // }
  3424. // else if (array[i] == '\'' && array[i - 1] != '\\') //wow '\\' is reading \' wow SO THE CODE READS ' and before that the last two characters are \\. cases like \"' work as expected before this fix. LATEST DEBUG 5:02 PM 11/20/2019
  3425. // {
  3426. // INASINGLEQUOTE = YES;
  3427. // i++;
  3428. //
  3429. // while (INASINGLEQUOTE == YES && array[i] != '\n' && array[i] != '\0' && array[i] != EOF) //if hex number must be 0-9 A-F until a space is read.
  3430. // {
  3431. // if (array[i] == '\'' && array[i - 1] != '\\') // && array[i-2] == "\""
  3432. // {
  3433. // INASINGLEQUOTE = NO;
  3434. // i++;
  3435. // }
  3436. // else if (array[i] == '\'' && array[i - 1] == '\\' && array[i - 2] == '\\')
  3437. // {
  3438. // INASINGLEQUOTE = NO;
  3439. // i++;
  3440. // }
  3441. // else
  3442. // {
  3443. // i++;
  3444. // }
  3445. // }
  3446. // if (INASINGLEQUOTE == YES)
  3447. // {
  3448. // INASINGLEQUOTE = NO;
  3449. // }
  3450. // }
  3451. // else if (array[i] == '"' && array[i - 1] != '\\')
  3452. // {
  3453. // INADOUBLEQUOTE = YES;
  3454. // i++;
  3455. // while (INADOUBLEQUOTE == YES && array[i] != '\n' && array[i] != '\0' && array[i] != EOF) //could use one variable INAQUOTE
  3456. // {
  3457. // if (array[i] == '"' && array[i - 1] != '\\')
  3458. // {
  3459. // INADOUBLEQUOTE = NO;
  3460. // i++;
  3461. // }
  3462. // else if (array[i] == '"' && array[i - 1] == '\\' && array[i - 2] == '\\')
  3463. // {
  3464. // INADOUBLEQUOTE = NO;
  3465. // i++;
  3466. // }
  3467. // else
  3468. // {
  3469. // i++;
  3470. // }
  3471. // }
  3472. // if (INADOUBLEQUOTE == YES)
  3473. // {
  3474. // INADOUBLEQUOTE = NO;
  3475. // }
  3476. // }
  3477. // else
  3478. // {
  3479. // if (array[i] == '\n')
  3480. // {
  3481. // LINE++;
  3482. // }
  3483. // i++;
  3484. // }
  3485. // }
  3486. //}
  3487. //
  3488. //void checkSingleQuotes(char array[])
  3489. //{
  3490. // int i = 0;
  3491. // char syntaxerror[MAXARRAYSIZE];
  3492. // int k = 0;
  3493. // int STAR = NO;
  3494. // int UNBALANCEDCOMMENT = NO;
  3495. // int INACOMMENT = NO;
  3496. // int LINE = 0;
  3497. // int INASINGLEQUOTE = NO;
  3498. // int SINGLEQUOTEBEGANON = 0;
  3499. // int INADOUBLEQUOTE = NO;
  3500. //
  3501. // while (array[i] != '\0' && array[i] != EOF)
  3502. // {
  3503. // if (array[i] == '\'' && array[i - 1] != '\\') /*wow '\\' is reading \' wow SO THE CODE READS ' and before that the last two characters are \\. cases like \"' work as expected before this fix. LATEST DEBUG 5:02 PM 11/20/2019*/
  3504. // {
  3505. // INASINGLEQUOTE = YES;
  3506. // SINGLEQUOTEBEGANON = LINE;
  3507. // i++;
  3508. //
  3509. // while (INASINGLEQUOTE == YES && array[i] != '\n' && array[i] != '\0' && array[i] != EOF) //if hex number must be 0-9 A-F until a space is read.
  3510. // {
  3511. // if (array[i] == '\'' && array[i - 1] != '\\') // && array[i-2] == "\""
  3512. // {
  3513. // INASINGLEQUOTE = NO;
  3514. // i++;
  3515. // }
  3516. // else if (array[i] == '\'' && array[i - 1] == '\\' && array[i - 2] == '\\')
  3517. // {
  3518. // INASINGLEQUOTE = NO;
  3519. // i++;
  3520. // }
  3521. // else
  3522. // {
  3523. // i++;
  3524. // }
  3525. // }
  3526. // if (INASINGLEQUOTE == YES)
  3527. // {
  3528. // printf("Error: Uneven single quote. The single quote that started on line %d is missing a single quote \'.\n", SINGLEQUOTEBEGANON);
  3529. // INASINGLEQUOTE = NO;
  3530. // }
  3531. // }
  3532. // else if (array[i] == '"' && array[i - 1] != '\\')
  3533. // {
  3534. // INADOUBLEQUOTE = YES;
  3535. // i++;
  3536. // while (INADOUBLEQUOTE == YES && array[i] != '\n' && array[i] != '\0' && array[i] != EOF) //could use one variable INAQUOTE
  3537. // {
  3538. // if (array[i] == '"' && array[i - 1] != '\\')
  3539. // {
  3540. // INADOUBLEQUOTE = NO;
  3541. // i++;
  3542. // }
  3543. // else if (array[i] == '"' && array[i - 1] == '\\' && array[i - 2] == '\\')
  3544. // {
  3545. // INADOUBLEQUOTE = NO;
  3546. // i++;
  3547. // }
  3548. // else
  3549. // {
  3550. // i++;
  3551. // }
  3552. // }
  3553. // if (INADOUBLEQUOTE == YES)
  3554. // {
  3555. // INADOUBLEQUOTE = NO;
  3556. // }
  3557. // }
  3558. // else if (array[i] == '/') //3 CASES
  3559. // {
  3560. // UNBALANCEDCOMMENT = YES; //CASE 1 DONE
  3561. //
  3562. // if (array[i + 1] == '/') //CASE 4
  3563. // {
  3564. // UNBALANCEDCOMMENT = NO;
  3565. // INACOMMENT = YES;
  3566. // while (array[i] != '\n' && array[i] != '\0' && array[i] != EOF)
  3567. // {
  3568. // i++;
  3569. // }
  3570. // INACOMMENT = NO;
  3571. // }
  3572. //
  3573. // else if (array[i + 1] == '*') //CASE 3
  3574. // {
  3575. // UNBALANCEDCOMMENT = YES;
  3576. // INACOMMENT = YES;
  3577. // i++;
  3578. // i++;
  3579. // while (INACOMMENT == YES && array[i] != '\0' && array[i] != EOF)
  3580. // {
  3581. // if (array[i] == '\n')
  3582. // {
  3583. // LINE++; //LINE COUNTER
  3584. // i++;
  3585. // }
  3586. // else if (array[i] == '*')
  3587. // {
  3588. // i++;
  3589. // STAR = YES;
  3590. // }
  3591. // else if (array[i] == '/' && STAR == YES)
  3592. // {
  3593. // i++;
  3594. // INACOMMENT = NO;
  3595. // UNBALANCEDCOMMENT = NO;
  3596. // STAR = NO;
  3597. // }
  3598. // else
  3599. // {
  3600. // i++;
  3601. // STAR = NO;
  3602. // }
  3603. // }
  3604. // }
  3605. // else
  3606. // {
  3607. // ;//NEXT CHARACTER IS HANDLED IN THE UNBALANCED COMMENT CODE BLOCK
  3608. // /*i++;
  3609. // j++;*/
  3610. // }
  3611. // if (UNBALANCEDCOMMENT == YES) //CASE 1
  3612. // {
  3613. // if (array[i] == '\n')
  3614. // {
  3615. // LINE++;
  3616. // }
  3617. // i++;
  3618. // UNBALANCEDCOMMENT = NO;
  3619. // }
  3620. //
  3621. // else if (UNBALANCEDCOMMENT == NO) //CASE 2
  3622. // {
  3623. // if (array[i] == '\n')
  3624. // {
  3625. // LINE++;
  3626. // }
  3627. // i++;
  3628. // }
  3629. // }
  3630. // else
  3631. // {
  3632. // if (array[i] == '\n')
  3633. // {
  3634. // LINE++;
  3635. // }
  3636. // i++;
  3637. // }
  3638. // }
  3639. //}
  3640. //
  3641. //void checkDoubleQuotes(char array[])
  3642. //{
  3643. // int i = 0;
  3644. // char syntaxerror[MAXARRAYSIZE];
  3645. // int k = 0;
  3646. // int STAR = NO;
  3647. // int UNBALANCEDCOMMENT = NO;
  3648. // int INACOMMENT = NO;
  3649. // int LINE = 0;
  3650. // int INADOUBLEQUOTE = NO;
  3651. // int DOUBLEQUOTEBEGANON = 0;
  3652. // int INASINGLEQUOTE = NO;
  3653. //
  3654. // while (array[i] != '\0' && array[i] != EOF)
  3655. // {
  3656. // if (array[i] == '"' && array[i - 1] != '\\')
  3657. // {
  3658. // INADOUBLEQUOTE = YES;
  3659. // DOUBLEQUOTEBEGANON = LINE; //could use one variable QUOTEBEGANON
  3660. // i++;
  3661. // while (INADOUBLEQUOTE == YES && array[i] != '\n' && array[i] != '\0' && array[i] != EOF) //could use one variable INAQUOTE
  3662. // {
  3663. // if (array[i] == '"' && array[i - 1] != '\\')
  3664. // {
  3665. // INADOUBLEQUOTE = NO;
  3666. // i++;
  3667. // }
  3668. // else if (array[i] == '"' && array[i - 1] == '\\' && array[i - 2] == '\\')
  3669. // {
  3670. // INADOUBLEQUOTE = NO;
  3671. // i++;
  3672. // }
  3673. // else
  3674. // {
  3675. // i++;
  3676. // }
  3677. // }
  3678. // if (INADOUBLEQUOTE == YES)
  3679. // {
  3680. // printf("Error: Uneven double quote. The double quote that started on line %d is missing a double quote \".\n", DOUBLEQUOTEBEGANON);
  3681. // INADOUBLEQUOTE = NO;
  3682. // }
  3683. // }
  3684. // else if (array[i] == '\'' && array[i - 1] != '\\') //wow '\\' is reading \' wow SO THE CODE READS ' and before that the last two characters are \\. cases like \"' work as expected before this fix. LATEST DEBUG 5:02 PM 11/20/2019
  3685. // {
  3686. // INASINGLEQUOTE = YES;
  3687. // i++;
  3688. //
  3689. // while (INASINGLEQUOTE == YES && array[i] != '\n' && array[i] != '\0' && array[i] != EOF) //if hex number must be 0-9 A-F until a space is read.
  3690. // {
  3691. // if (array[i] == '\'' && array[i - 1] != '\\') // && array[i-2] == "\""
  3692. // {
  3693. // INASINGLEQUOTE = NO;
  3694. // i++;
  3695. // }
  3696. // else if (array[i] == '\'' && array[i - 1] == '\\' && array[i - 2] == '\\')
  3697. // {
  3698. // INASINGLEQUOTE = NO;
  3699. // i++;
  3700. // }
  3701. // else
  3702. // {
  3703. // i++;
  3704. // }
  3705. // }
  3706. // if (INASINGLEQUOTE == YES)
  3707. // {
  3708. // INASINGLEQUOTE = NO;
  3709. // }
  3710. // }
  3711. // else if (array[i] == '/') //3 CASES
  3712. // {
  3713. // UNBALANCEDCOMMENT = YES; //CASE 1 DONE
  3714. //
  3715. // if (array[i + 1] == '/') //CASE 4
  3716. // {
  3717. // UNBALANCEDCOMMENT = NO;
  3718. // INACOMMENT = YES;
  3719. // while (array[i] != '\n' && array[i] != '\0' && array[i] != EOF)
  3720. // {
  3721. // i++;
  3722. // }
  3723. // INACOMMENT = NO;
  3724. // }
  3725. //
  3726. // else if (array[i + 1] == '*') //CASE 3
  3727. // {
  3728. // UNBALANCEDCOMMENT = YES;
  3729. // INACOMMENT = YES;
  3730. // i++;
  3731. // i++;
  3732. // while (INACOMMENT == YES && array[i] != '\0' && array[i] != EOF)
  3733. // {
  3734. // if (array[i] == '\n')
  3735. // {
  3736. // LINE++; //LINE COUNTER
  3737. // i++;
  3738. // }
  3739. // else if (array[i] == '*')
  3740. // {
  3741. // i++;
  3742. // STAR = YES;
  3743. // }
  3744. // else if (array[i] == '/' && STAR == YES)
  3745. // {
  3746. // i++;
  3747. // INACOMMENT = NO;
  3748. // UNBALANCEDCOMMENT = NO;
  3749. // STAR = NO;
  3750. // }
  3751. // else
  3752. // {
  3753. // i++;
  3754. // STAR = NO;
  3755. // }
  3756. // }
  3757. // }
  3758. // else
  3759. // {
  3760. // ;//NEXT CHARACTER HANDLED IN THE UNBALANCED COMMENT BLOCK
  3761. // /*i++;
  3762. // j++;*/
  3763. // }
  3764. // if (UNBALANCEDCOMMENT == YES) //CASE 1
  3765. // {
  3766. // if (array[i] == '\n')
  3767. // {
  3768. // LINE++;
  3769. // }
  3770. // i++;
  3771. // UNBALANCEDCOMMENT = NO;
  3772. // }
  3773. //
  3774. // else if (UNBALANCEDCOMMENT == NO) //CASE 2
  3775. // {
  3776. // if (array[i] == '\n')
  3777. // {
  3778. // LINE++;
  3779. // }
  3780. // i++;
  3781. // }
  3782. // }
  3783. // else
  3784. // {
  3785. // if (array[i] == '\n')
  3786. // {
  3787. // LINE++;
  3788. // }
  3789. // i++;
  3790. // }
  3791. // }
  3792. //}
  3793. //
  3794. //void checkHexidecimalEscapeSequences(char array[])
  3795. //{
  3796. // int i = 0;
  3797. // char syntaxerror[MAXARRAYSIZE];
  3798. // int k = 0;
  3799. // int STAR = NO;
  3800. // int UNBALANCEDCOMMENT = NO;
  3801. // int INACOMMENT = NO;
  3802. // int LINE = 0;
  3803. // int INASINGLEQUOTE = NO;
  3804. // int INADOUBLEQUOTE = NO;
  3805. // int HEXSYNTAXERROR = NO;
  3806. // int HEXSYNTAXERRORBEGANON = 0;
  3807. //
  3808. // while (array[i] != '\0' && array[i] != EOF)
  3809. // {
  3810. // if (array[i] == '\'' && array[i - 1] != '\\') //wow '\\' is reading \' wow SO THE CODE READS ' and before that the last two characters are \\. cases like \"' work as expected before this fix. LATEST DEBUG 5:02 PM 11/20/2019
  3811. // {
  3812. // INASINGLEQUOTE = YES;
  3813. // i++;
  3814. //
  3815. // while (INASINGLEQUOTE == YES && array[i] != '\n') //if hex number must be 0-9 A-F until a space is read.
  3816. // {
  3817. // if (array[i] == '\'' && array[i - 1] != '\\') // && array[i-2] == "\""
  3818. // {
  3819. // INASINGLEQUOTE = NO;
  3820. // i++;
  3821. // }
  3822. // else if (array[i] == '\'' && array[i - 1] == '\\' && array[i - 2] == '\\')
  3823. // {
  3824. // INASINGLEQUOTE = NO;
  3825. // i++;
  3826. // }
  3827. // else if (array[i] == 'x' && array[i - 1] == '\\' && array[i - 2] != '\\')
  3828. // {
  3829. // i++;
  3830. // while (array[i] != ' ' && array[i] != '\'' && array[i] != '\n')
  3831. // {
  3832. // if (array[i] != '0' && array[i] != '1' && array[i] != '2' && array[i] != '3' && array[i] != '4' && array[i] != '5' && array[i] != '6' && array[i] != '7' && array[i] != '8' && array[i] != '9' && array[i] != 'A' && array[i] != 'B' && array[i] != 'C' && array[i] != 'D' && array[i] != 'E' && array[i] != 'F')
  3833. // {
  3834. // HEXSYNTAXERROR = YES;
  3835. // HEXSYNTAXERRORBEGANON = LINE;
  3836. // }
  3837. // i++;
  3838. // }
  3839. // }
  3840. // else
  3841. // {
  3842. // i++;
  3843. // }
  3844. // }
  3845. // if (INASINGLEQUOTE == YES)
  3846. // {
  3847. // INASINGLEQUOTE = NO;
  3848. // }
  3849. // if (HEXSYNTAXERROR == YES)
  3850. // {
  3851. // printf("Error: Syntax error. The hexidecimal number in the single quotes on line %d is not acceptable.\n", HEXSYNTAXERRORBEGANON);
  3852. // HEXSYNTAXERROR = NO;
  3853. // }
  3854. // }
  3855. // else if (array[i] == '"' && array[i - 1] != '\\')
  3856. // {
  3857. // INADOUBLEQUOTE = YES;
  3858. // i++;
  3859. // while (INADOUBLEQUOTE == YES && array[i] != '\n') //could use one variable INAQUOTE
  3860. // {
  3861. // if (array[i] == '"' && array[i - 1] != '\\')
  3862. // {
  3863. // INADOUBLEQUOTE = NO;
  3864. // i++;
  3865. // }
  3866. // else if (array[i] == '"' && array[i - 1] == '\\' && array[i - 2] == '\\')
  3867. // {
  3868. // INADOUBLEQUOTE = NO;
  3869. // i++;
  3870. // }
  3871. // else if (array[i] == 'x' && array[i - 1] == '\\' && array[i - 2] != '\\')
  3872. // {
  3873. // i++;
  3874. // while (array[i] != ' ' && array[i] != '\'' && array[i] != '\n')
  3875. // {
  3876. // if (array[i] != '0' && array[i] != '1' && array[i] != '2' && array[i] != '3' && array[i] != '4' && array[i] != '5' && array[i] != '6' && array[i] != '7' && array[i] != '8' && array[i] != '9' && array[i] != 'A' && array[i] != 'B' && array[i] != 'C' && array[i] != 'D' && array[i] != 'E' && array[i] != 'F')
  3877. // {
  3878. // HEXSYNTAXERROR = YES;
  3879. // HEXSYNTAXERRORBEGANON = LINE;
  3880. // }
  3881. // i++;
  3882. // }
  3883. // }
  3884. // else
  3885. // {
  3886. // i++;
  3887. // }
  3888. // }
  3889. // if (INADOUBLEQUOTE == YES)
  3890. // {
  3891. // INADOUBLEQUOTE = NO;
  3892. // }
  3893. // if (HEXSYNTAXERROR == YES)
  3894. // {
  3895. // printf("Error: Syntax error. The hexidecimal number in the double quotes on line %d is not acceptable.\n", HEXSYNTAXERRORBEGANON);
  3896. // HEXSYNTAXERROR = NO;
  3897. // }
  3898. // }
  3899. // else if (array[i] == '/') //3 CASES
  3900. // {
  3901. // UNBALANCEDCOMMENT = YES; //CASE 1 DONE
  3902. //
  3903. // if (array[i + 1] == '/') //CASE 4
  3904. // {
  3905. // UNBALANCEDCOMMENT = NO;
  3906. // INACOMMENT = YES;
  3907. // while (array[i] != '\n')
  3908. // {
  3909. // i++;
  3910. // }
  3911. // INACOMMENT = NO;
  3912. // }
  3913. //
  3914. // else if (array[i + 1] == '*') //CASE 3
  3915. // {
  3916. // UNBALANCEDCOMMENT = YES;
  3917. // INACOMMENT = YES;
  3918. // i++;
  3919. // i++;
  3920. // while (INACOMMENT == YES && array[i] != '\0')
  3921. // {
  3922. // if (array[i] == '\n')
  3923. // {
  3924. // LINE++; //LINE COUNTER
  3925. // i++;
  3926. // }
  3927. // else if (array[i] == '*')
  3928. // {
  3929. // i++;
  3930. // STAR = YES;
  3931. // }
  3932. // else if (array[i] == '/' && STAR == YES)
  3933. // {
  3934. // i++;
  3935. // INACOMMENT = NO;
  3936. // UNBALANCEDCOMMENT = NO;
  3937. // STAR = NO;
  3938. // }
  3939. // else
  3940. // {
  3941. // i++;
  3942. // STAR = NO;
  3943. // }
  3944. // }
  3945. // }
  3946. // else
  3947. // {
  3948. // ;//NEXT CHARACTER HANDLED IN THE UNBALANCED COMMENT CODE BLOCK
  3949. // /*i++;
  3950. // j++;*/
  3951. // }
  3952. // if (UNBALANCEDCOMMENT == YES) //CASE 1
  3953. // {
  3954. // if (array[i] == '\n')
  3955. // {
  3956. // LINE++;
  3957. // }
  3958. // i++;
  3959. // UNBALANCEDCOMMENT = NO;
  3960. // }
  3961. //
  3962. // else if (UNBALANCEDCOMMENT == NO) //CASE 2
  3963. // {
  3964. // if (array[i] == '\n')
  3965. // {
  3966. // LINE++;
  3967. // }
  3968. // i++;
  3969. // }
  3970. // }
  3971. // else
  3972. // {
  3973. // if (array[i] == '\n')
  3974. // {
  3975. // LINE++;
  3976. // }
  3977. // i++;
  3978. // }
  3979. // }
  3980. //}
  3981. //
  3982. //void checkBrackets(char array[])
  3983. //{
  3984. // int i = 0;
  3985. // int LeftBrackets = 0;
  3986. // int RightBrackets = 0;
  3987. // int EXTRALEFTBRACKETONLINE = 0;
  3988. // int EXTRARIGHTBRACKETONLINE = 0;
  3989. // int STAR = NO;
  3990. // int UNBALANCEDCOMMENT = NO;
  3991. // int INACOMMENT = NO;
  3992. // int LINE = 0;
  3993. // int INASINGLEQUOTE = NO;
  3994. // int INADOUBLEQUOTE = NO;
  3995. //
  3996. // while (array[i] != '\0' && array[i] != EOF)
  3997. // {
  3998. // if (array[i] == '[')
  3999. // {
  4000. // LeftBrackets++;
  4001. // EXTRALEFTBRACKETONLINE = LINE;
  4002. // i++;
  4003. // if (LeftBrackets - RightBrackets > 1)
  4004. // {
  4005. // printf("Error: Uneven brackets. An extra [ was found on line %d.\n", EXTRALEFTBRACKETONLINE);
  4006. // }
  4007. // }
  4008. // else if (array[i] == ']')
  4009. // {
  4010. // RightBrackets++;
  4011. // EXTRARIGHTBRACKETONLINE = LINE;
  4012. // i++;
  4013. // if (RightBrackets - LeftBrackets > 0)
  4014. // {
  4015. // printf("Error: Uneven brackets. An extra ] was found on line %d.\n", EXTRARIGHTBRACKETONLINE);
  4016. // }
  4017. // }
  4018. // else if (array[i] == '\'' && array[i - 1] != '\\') //wow '\\' is reading \' wow SO THE CODE READS ' and before that the last two characters are \\. cases like \"' work as expected before this fix. LATEST DEBUG 5:02 PM 11/20/2019
  4019. // {
  4020. // INASINGLEQUOTE = YES;
  4021. // i++;
  4022. //
  4023. // while (INASINGLEQUOTE == YES && array[i] != '\n') //if hex number must be 0-9 A-F until a space is read.
  4024. // {
  4025. // if (array[i] == '\'' && array[i - 1] != '\\') // && array[i-2] == "\""
  4026. // {
  4027. // INASINGLEQUOTE = NO;
  4028. // i++;
  4029. // }
  4030. // else if (array[i] == '\'' && array[i - 1] == '\\' && array[i - 2] == '\\')
  4031. // {
  4032. // INASINGLEQUOTE = NO;
  4033. // i++;
  4034. // }
  4035. // else
  4036. // {
  4037. // i++;
  4038. // }
  4039. // }
  4040. // if (INASINGLEQUOTE == YES)
  4041. // {
  4042. // INASINGLEQUOTE = NO;
  4043. // }
  4044. // }
  4045. // else if (array[i] == '"' && array[i - 1] != '\\')
  4046. // {
  4047. // INADOUBLEQUOTE = YES;
  4048. // i++;
  4049. // while (INADOUBLEQUOTE == YES && array[i] != '\n') //could use one variable INAQUOTE
  4050. // {
  4051. // if (array[i] == '"' && array[i - 1] != '\\')
  4052. // {
  4053. // INADOUBLEQUOTE = NO;
  4054. // i++;
  4055. // }
  4056. // else if (array[i] == '"' && array[i - 1] == '\\' && array[i - 2] == '\\')
  4057. // {
  4058. // INADOUBLEQUOTE = NO;
  4059. // i++;
  4060. // }
  4061. // else
  4062. // {
  4063. // i++;
  4064. // }
  4065. // }
  4066. // if (INADOUBLEQUOTE == YES)
  4067. // {
  4068. // INADOUBLEQUOTE = NO;
  4069. // }
  4070. // }
  4071. // else if (array[i] == '/') //3 CASES
  4072. // {
  4073. // UNBALANCEDCOMMENT = YES; //CASE 1 DONE
  4074. //
  4075. // if (array[i + 1] == '/') //CASE 4
  4076. // {
  4077. // UNBALANCEDCOMMENT = NO;
  4078. // INACOMMENT = YES;
  4079. // while (array[i] != '\n')
  4080. // {
  4081. // i++;
  4082. // }
  4083. // INACOMMENT = NO;
  4084. // }
  4085. //
  4086. // else if (array[i + 1] == '*') //CASE 3
  4087. // {
  4088. // UNBALANCEDCOMMENT = YES;
  4089. // INACOMMENT = YES;
  4090. // i++;
  4091. // i++;
  4092. // while (INACOMMENT == YES && array[i] != '\0')
  4093. // {
  4094. // if (array[i] == '\n')
  4095. // {
  4096. // LINE++; //LINE COUNTER
  4097. // i++;
  4098. // }
  4099. // else if (array[i] == '*')
  4100. // {
  4101. // i++;
  4102. // STAR = YES;
  4103. // }
  4104. // else if (array[i] == '/' && STAR == YES)
  4105. // {
  4106. // i++;
  4107. // INACOMMENT = NO;
  4108. // UNBALANCEDCOMMENT = NO;
  4109. // STAR = NO;
  4110. // }
  4111. // else
  4112. // {
  4113. // i++;
  4114. // STAR = NO;
  4115. // }
  4116. // }
  4117. // }
  4118. // else
  4119. // {
  4120. // ; //NEXT CHARACTER HANDLED IN THE UNBALANCED COMMENT CODE BLOCK
  4121. // /*i++;
  4122. // j++;*/
  4123. // }
  4124. // if (UNBALANCEDCOMMENT == YES) //CASE 1
  4125. // {
  4126. // if (array[i] == '\n')
  4127. // {
  4128. // LINE++;
  4129. // }
  4130. // i++;
  4131. // UNBALANCEDCOMMENT = NO;
  4132. // }
  4133. // else if (UNBALANCEDCOMMENT == NO) //CASE 2
  4134. // {
  4135. // if (array[i] == '\n')
  4136. // {
  4137. // LINE++;
  4138. // }
  4139. // i++;
  4140. // }
  4141. // }
  4142. // else
  4143. // {
  4144. // if (array[i] == '\n')
  4145. // {
  4146. // LINE++;
  4147. // LeftBrackets = 0;
  4148. // RightBrackets = 0;
  4149. // }
  4150. // i++;
  4151. // }
  4152. // }
  4153. //}
  4154. //
  4155. //void checkParenthesis(char array[])
  4156. //{
  4157. // int i = 0;
  4158. // int LeftParenthesis = 0;
  4159. // int RightParenthesis = 0;
  4160. // int EXTRALEFTPARENTHESISONLINE = 0;
  4161. // int EXTRARIGHTPARENTHESISONLINE = 0;
  4162. // int STAR = NO;
  4163. // int UNBALANCEDCOMMENT = NO;
  4164. // int INACOMMENT = NO;
  4165. // int LINE = 0;
  4166. // int INASINGLEQUOTE = NO;
  4167. // int INADOUBLEQUOTE = NO;
  4168. //
  4169. // while (array[i] != '\0' && array[i] != EOF)
  4170. // {
  4171. // if (array[i] == '(')
  4172. // {
  4173. // LeftParenthesis++;
  4174. // EXTRALEFTPARENTHESISONLINE = LINE;
  4175. //
  4176. // i++;
  4177. // }
  4178. // else if (array[i] == ')')
  4179. // {
  4180. // RightParenthesis++;
  4181. // EXTRARIGHTPARENTHESISONLINE = LINE;
  4182. //
  4183. // i++;
  4184. // if (RightParenthesis > LeftParenthesis)
  4185. // {
  4186. // printf("Error: Uneven Right Parenthesis ). An extra ) was found on line %d.\n", EXTRARIGHTPARENTHESISONLINE);
  4187. // }
  4188. // }
  4189. // else if (array[i] == '\'' && array[i - 1] != '\\') //wow '\\' is reading \' wow SO THE CODE READS ' and before that the last two characters are \\. cases like \"' work as expected before this fix. LATEST DEBUG 5:02 PM 11/20/2019
  4190. // {
  4191. // INASINGLEQUOTE = YES;
  4192. // i++;
  4193. //
  4194. // while (INASINGLEQUOTE == YES && array[i] != '\n') //if hex number must be 0-9 A-F until a space is read.
  4195. // {
  4196. // if (array[i] == '\'' && array[i - 1] != '\\') // && array[i-2] == "\""
  4197. // {
  4198. // INASINGLEQUOTE = NO;
  4199. // i++;
  4200. // }
  4201. // else if (array[i] == '\'' && array[i - 1] == '\\' && array[i - 2] == '\\')
  4202. // {
  4203. // INASINGLEQUOTE = NO;
  4204. // i++;
  4205. // }
  4206. // else
  4207. // {
  4208. // i++;
  4209. // }
  4210. // }
  4211. // if (INASINGLEQUOTE == YES)
  4212. // {
  4213. // INASINGLEQUOTE = NO;
  4214. // }
  4215. // }
  4216. // else if (array[i] == '"' && array[i - 1] != '\\')
  4217. // {
  4218. // INADOUBLEQUOTE = YES;
  4219. // i++;
  4220. // while (INADOUBLEQUOTE == YES && array[i] != '\n') //could use one variable INAQUOTE
  4221. // {
  4222. // if (array[i] == '"' && array[i - 1] != '\\')
  4223. // {
  4224. // INADOUBLEQUOTE = NO;
  4225. // i++;
  4226. // }
  4227. // else if (array[i] == '"' && array[i - 1] == '\\' && array[i - 2] == '\\')
  4228. // {
  4229. // INADOUBLEQUOTE = NO;
  4230. // i++;
  4231. // }
  4232. // else
  4233. // {
  4234. // i++;
  4235. // }
  4236. // }
  4237. // if (INADOUBLEQUOTE == YES)
  4238. // {
  4239. // INADOUBLEQUOTE = NO;
  4240. // }
  4241. // }
  4242. // else if (array[i] == '/') //3 CASES
  4243. // {
  4244. // UNBALANCEDCOMMENT = YES; //CASE 1 DONE
  4245. //
  4246. // if (array[i + 1] == '/') //CASE 4
  4247. // {
  4248. // UNBALANCEDCOMMENT = NO;
  4249. // INACOMMENT = YES;
  4250. // while (array[i] != '\n')
  4251. // {
  4252. // i++;
  4253. // }
  4254. // INACOMMENT = NO;
  4255. // }
  4256. //
  4257. // else if (array[i + 1] == '*') //CASE 3
  4258. // {
  4259. // UNBALANCEDCOMMENT = YES;
  4260. // INACOMMENT = YES;
  4261. // i++;
  4262. // i++;
  4263. // while (INACOMMENT == YES && array[i] != '\0')
  4264. // {
  4265. // if (array[i] == '\n')
  4266. // {
  4267. // LINE++; //LINE COUNTER
  4268. // i++;
  4269. // }
  4270. // else if (array[i] == '*')
  4271. // {
  4272. // i++;
  4273. // STAR = YES;
  4274. // }
  4275. // else if (array[i] == '/' && STAR == YES)
  4276. // {
  4277. // i++;
  4278. // INACOMMENT = NO;
  4279. // UNBALANCEDCOMMENT = NO;
  4280. // STAR = NO;
  4281. // }
  4282. // else
  4283. // {
  4284. // i++;
  4285. // STAR = NO;
  4286. // }
  4287. // }
  4288. // }
  4289. // else
  4290. // {
  4291. // ; //NEXT CHARACTER HANDLED IN THE UNBALANCED COMMENT CODE BLOCK
  4292. // /*i++;
  4293. // j++;*/
  4294. // }
  4295. // if (UNBALANCEDCOMMENT == YES) //CASE 1
  4296. // {
  4297. // if (array[i] == '\n')
  4298. // {
  4299. // LINE++;
  4300. // }
  4301. // i++;
  4302. // UNBALANCEDCOMMENT = NO;
  4303. // }
  4304. // else if (UNBALANCEDCOMMENT == NO) //CASE 2
  4305. // {
  4306. // if (array[i] == '\n')
  4307. // {
  4308. // LINE++;
  4309. // }
  4310. // i++;
  4311. // }
  4312. // }
  4313. // else
  4314. // {
  4315. // if (array[i] == '\n')
  4316. // {
  4317. // LINE++;
  4318. // if (LeftParenthesis > RightParenthesis)
  4319. // {
  4320. // printf("Error: Uneven Left Parenthesis (. An extra ( was found on line %d.\n", EXTRALEFTPARENTHESISONLINE);
  4321. // }
  4322. // LeftParenthesis = 0;
  4323. // RightParenthesis = 0;
  4324. // }
  4325. // i++;
  4326. // }
  4327. // }
  4328. //}
  4329. //
  4330. //void checkBraces(char array[])
  4331. //{
  4332. // int i = 0;
  4333. // int LeftBraces = 0;
  4334. // int RightBraces = 0;
  4335. // int EXTRALEFTBRACEONLINE = 0;
  4336. // int EXTRARIGHTBRACEONLINE = 0;
  4337. // int STAR = NO;
  4338. // int UNBALANCEDCOMMENT = NO;
  4339. // int INACOMMENT = NO;
  4340. // int LINE = 0;
  4341. // int INASINGLEQUOTE = NO;
  4342. // int INADOUBLEQUOTE = NO;
  4343. //
  4344. // while (array[i] != '\0' && array[i] != EOF)
  4345. // {
  4346. // if (array[i] == '{')
  4347. // {
  4348. // LeftBraces++;
  4349. // EXTRALEFTBRACEONLINE = LINE;
  4350. // i++;
  4351. // }
  4352. // else if (array[i] == '}')
  4353. // {
  4354. // RightBraces++;
  4355. // EXTRARIGHTBRACEONLINE = LINE;
  4356. // i++;
  4357. // if (RightBraces - LeftBraces > 0)
  4358. // {
  4359. // printf("Error: Uneven Right Braces. An extra } was found on line %d.\n", EXTRARIGHTBRACEONLINE);
  4360. // }
  4361. // }
  4362. // else if (array[i] == '\'' && array[i - 1] != '\\') //wow '\\' is reading \' wow SO THE CODE READS ' and before that the last two characters are \\. cases like \"' work as expected before this fix. LATEST DEBUG 5:02 PM 11/20/2019
  4363. // {
  4364. // INASINGLEQUOTE = YES;
  4365. // i++;
  4366. //
  4367. // while (INASINGLEQUOTE == YES && array[i] != '\n') //if hex number must be 0-9 A-F until a space is read.
  4368. // {
  4369. // if (array[i] == '\'' && array[i - 1] != '\\') // && array[i-2] == "\""
  4370. // {
  4371. // INASINGLEQUOTE = NO;
  4372. // i++;
  4373. // }
  4374. // else if (array[i] == '\'' && array[i - 1] == '\\' && array[i - 2] == '\\')
  4375. // {
  4376. // INASINGLEQUOTE = NO;
  4377. // i++;
  4378. // }
  4379. // else
  4380. // {
  4381. // i++;
  4382. // }
  4383. // }
  4384. // if (INASINGLEQUOTE == YES)
  4385. // {
  4386. // INASINGLEQUOTE = NO;
  4387. // }
  4388. // }
  4389. // else if (array[i] == '"' && array[i - 1] != '\\')
  4390. // {
  4391. // INADOUBLEQUOTE = YES;
  4392. // i++;
  4393. // while (INADOUBLEQUOTE == YES && array[i] != '\n') //could use one variable INAQUOTE
  4394. // {
  4395. // if (array[i] == '"' && array[i - 1] != '\\')
  4396. // {
  4397. // INADOUBLEQUOTE = NO;
  4398. // i++;
  4399. // }
  4400. // else if (array[i] == '"' && array[i - 1] == '\\' && array[i - 2] == '\\')
  4401. // {
  4402. // INADOUBLEQUOTE = NO;
  4403. // i++;
  4404. // }
  4405. // else
  4406. // {
  4407. // i++;
  4408. // }
  4409. // }
  4410. // if (INADOUBLEQUOTE == YES)
  4411. // {
  4412. // INADOUBLEQUOTE = NO;
  4413. // }
  4414. // }
  4415. // else if (array[i] == '/') //3 CASES
  4416. // {
  4417. // UNBALANCEDCOMMENT = YES; //CASE 1 DONE
  4418. //
  4419. // if (array[i + 1] == '/') //CASE 4
  4420. // {
  4421. // UNBALANCEDCOMMENT = NO;
  4422. // INACOMMENT = YES;
  4423. // while (array[i] != '\n')
  4424. // {
  4425. // i++;
  4426. // }
  4427. // INACOMMENT = NO;
  4428. // }
  4429. //
  4430. // else if (array[i + 1] == '*') //CASE 3
  4431. // {
  4432. // UNBALANCEDCOMMENT = YES;
  4433. // INACOMMENT = YES;
  4434. // i++;
  4435. // i++;
  4436. // while (INACOMMENT == YES && array[i] != '\0')
  4437. // {
  4438. // if (array[i] == '\n')
  4439. // {
  4440. // LINE++; //LINE COUNTER
  4441. // i++;
  4442. // }
  4443. // else if (array[i] == '*')
  4444. // {
  4445. // i++;
  4446. // STAR = YES;
  4447. // }
  4448. // else if (array[i] == '/' && STAR == YES)
  4449. // {
  4450. // i++;
  4451. // INACOMMENT = NO;
  4452. // UNBALANCEDCOMMENT = NO;
  4453. // STAR = NO;
  4454. // }
  4455. // else
  4456. // {
  4457. // i++;
  4458. // STAR = NO;
  4459. // }
  4460. // }
  4461. // }
  4462. // else
  4463. // {
  4464. // ; //NEXT CHARACTER HANDLED IN THE UNBALANCED COMMENT CODE BLOCK
  4465. // /*i++;
  4466. // j++;*/
  4467. // }
  4468. // if (UNBALANCEDCOMMENT == YES) //CASE 1
  4469. // {
  4470. // if (array[i] == '\n')
  4471. // {
  4472. // LINE++;
  4473. // }
  4474. // i++;
  4475. // UNBALANCEDCOMMENT = NO;
  4476. // }
  4477. // else if (UNBALANCEDCOMMENT == NO) //CASE 2
  4478. // {
  4479. // if (array[i] == '\n')
  4480. // {
  4481. // LINE++;
  4482. // }
  4483. // i++;
  4484. // }
  4485. // }
  4486. // else
  4487. // {
  4488. // if (array[i] == '\n')
  4489. // {
  4490. // LINE++;
  4491. // }
  4492. // i++;
  4493. // }
  4494. // }
  4495. // if (LeftBraces > RightBraces)
  4496. // {
  4497. // printf("Error: Uneven amount of Left Braces {. An extra left brace ({) was found on line %d.\n", EXTRALEFTBRACEONLINE);
  4498. // printf("Total number of extra left braces: %d\n", LeftBraces - RightBraces);
  4499. // }
  4500. //}
  4501. //
  4502. //main()
  4503. //{
  4504. /*unsigned int c = 0;
  4505. c--;
  4506. printf("%d", c);*/
  4507. //unsigned int c = 1; //It's about the interpretation that printf gives to the parameter you pass.
  4508. //while (c > 0)
  4509. // c++;
  4510. //c--;
  4511. //printf("%d", c);
  4512. //while (c > 0)
  4513. // c++;
  4514. //printf("%d", c); //It's about the interpretation that printf gives to the parameter you pass.
  4515. //}
  4516. //main()
  4517. //{
  4518. // unsigned char c = 0; //1 bytes 2^8 unsigned char is q byte on this machine
  4519. // c--;
  4520. // printf("%u", c);
  4521. //}
  4522. //main()
  4523. //{
  4524. // signed char c = 1; //1 bytes -2^7 to 2^7 - 1 signed char is q byte on this machine
  4525. // while (c > 0)
  4526. // c++;
  4527. // c--;
  4528. // printf("%c", c); //%c causes unexpected results //%c prints a character, not the decimal representation of an integer. If you want to print the decimal representation of an integer, use %d.
  4529. // printf("\n");
  4530. // printf("%d", c);
  4531. //}
  4532. //main()
  4533. //{
  4534. // unsigned int c = 0; //4 bytes 2^32 unsigned int is 4 bytes on this machine
  4535. // c--;
  4536. // printf("%u", c);
  4537. //}
  4538. //main()
  4539. //{
  4540. // signed int c = 1; //4 bytes -2^32 to 2^32 - 1 signed int is 4 bytes on this machine
  4541. // while (c > 0)
  4542. // c++;
  4543. // c--;
  4544. // printf("%d", c);
  4545. //}
  4546. //Experiment
  4547. //Valuable result: unsigned and signed data type use the same number of bytes. The escape sequence %c prints out the character at the position of the numerical value in the character set of the system of the numerical value of the character passed to it.
  4548. //main()
  4549. //{
  4550. // char zero = 0;
  4551. // char A = 65;
  4552. // printf("%c", zero); //prints NULL and not 0
  4553. // printf("\n");
  4554. // printf("%d", zero); //prints the decimal representation of an integer (char 0; a small integer)
  4555. // printf("\n");
  4556. // printf("%c", A); //prints A and not 65
  4557. // printf("\n");
  4558. // printf("%d", A); //prints the decimal representation of an integer (char 65; a small integer)
  4559. //}
  4560. //Experiment
  4561. //Valueable result: character is a small integer. Use %c to print out the character represented by the numerical value in the character set of the computer of the numerical value of the character passed to it. Use %d to print out the decimal representation of an integer.
  4562. //main()
  4563. //{
  4564. // char zero = 0;
  4565. // char A = 65;
  4566. // printf("%c %d\n", A - zero, A - zero);
  4567. // printf("%c %d\n", A - 0, A - 0); //
  4568. // printf("%c %d\n", A - '0', A - '0');
  4569. // zero = '0';
  4570. // A = 65;
  4571. // printf("%c %d\n", A - zero, A - zero);
  4572. // printf("%c %d\n", A - 0, A - 0); //
  4573. // printf("%c %d\n", A - '0', A - '0');
  4574. //}
  4575. //Experiment
  4576. //Valuable result: the integer 0 stored in variable character zero is different than the character 0 ('0') stored in the variable (character zero). The definition of the variable is directly related to the programs operation(s).
  4577. //main()
  4578. //{
  4579. // char zero = getchar();
  4580. // char A = 65;
  4581. // printf("%c %d\n", A - zero, A - zero);
  4582. // printf("%c %d\n", A - 0, A - 0); //
  4583. // printf("%c %d\n", A - '0', A - '0');
  4584. // zero = '0';
  4585. // A = 65;
  4586. // printf("%c %d\n", A - zero, A - zero);
  4587. // printf("%c %d\n", A - 0, A - 0); //
  4588. // printf("%c %d\n", A - '0', A - '0');
  4589. //}
  4590. //Experiment
  4591. //Valueable result: getchar grabs '0' and '1' not integers 0 and 1. getchar() GRABS CHARACTERS AND NOT INTEGERS!
  4592. //main()
  4593. //{
  4594. // char zero = getchar();
  4595. // char A = 65;
  4596. // printf("%c %d\n", A - (zero - '0'), A - (zero - '0'));
  4597. // printf("%c %d\n", A - 0, A - 0); //
  4598. // printf("%c %d\n", A - '0', A - '0');
  4599. // zero = '0';
  4600. // A = 65;
  4601. // printf("%c %d\n", A - zero, A - zero);
  4602. // printf("%c %d\n", A - 0, A - 0); //
  4603. // printf("%c %d\n", A - '0', A - '0');
  4604. //
  4605. // printf("%c %d\n", A - (zero - '0'), A - (zero - '0'));
  4606. // printf("%c %d\n", A - 0, A - 0);
  4607. // printf("%c %d\n", A - '0', A - '0');
  4608. //}
  4609. //Experiment
  4610. //Valueable result: arithmetic can be used to effectively produce integers from getchar(), like A - (zero - '0')
  4611. //main()
  4612. //{
  4613. // char zero = getchar();
  4614. // char A = 65;
  4615. // printf("%c %d\n", A - (zero - '0'), A - (zero - '0'));
  4616. // printf("%c %d\n", A - 0, A - 0); //
  4617. // printf("%c %d\n", A - '0', A - '0');
  4618. // zero = 'A';
  4619. // A = 65;
  4620. // printf("%c %d\n", A - zero, A - zero);
  4621. // printf("%c %d\n", A - 0, A - 0); //
  4622. // printf("%c %d\n", A - '0', A - '0');
  4623. //}
  4624. //Experiment
  4625. //Valueable result: chacacter read by getchar display character that are defined by small integers and can be implemented into arithmetic
  4626. //unsigned and signed short and long (int), float, double, and long double
  4627. //main()
  4628. //{
  4629. // unsigned short int number = 1; //short is 2 bytes 2^16 = 65535
  4630. // while (number > 0)
  4631. // number++;
  4632. // number--;
  4633. // printf("%u", number);
  4634. //}
  4635. //main()
  4636. //{
  4637. // signed short int number = 1; //short is 2 bytes 2^16-1 to 2^16-1 - 1 = -32768 to 32767
  4638. // while (number > 0)
  4639. // number++;
  4640. // number--;
  4641. // printf("%d", number);
  4642. //}
  4643. //main()
  4644. //{
  4645. // unsigned long int number = 0; //long is 4 bytes 2^32 = 4.29e9
  4646. // /*while (number > 0)
  4647. // number++;*/
  4648. // number--;
  4649. // printf("%u", number);
  4650. //}
  4651. //main()
  4652. //{
  4653. // signed long int number = 1; //long is 4 bytes 2^32-1 = -4.29e9/2 to 4.29e9/2 - 1
  4654. // while (number > 0)
  4655. // number++;
  4656. // //number--;
  4657. // printf("%d", number);
  4658. //}
  4659. //main()
  4660. //{
  4661. // float number = 1;
  4662. // while (number > 0)
  4663. // number++;
  4664. // number--;
  4665. // printf("%f", number);
  4666. //}
  4667. //Valuable result: float does not wrap it goes to infinity. #define FLT_MAX 3.402823466e+38F // max value #define FLT_MIN 1.175494351e-38F // min normalized positive value
  4668. //main()
  4669. //{
  4670. // double number = 99999.1;
  4671. // while (number > 0)
  4672. // {
  4673. // number++;
  4674. // printf("%f\n", number); //fixed.point notation infinity and nan
  4675. // printf("%e\n", number); //standard form e+00
  4676. // printf("%g\n", number); //Normal or exponent notation, whichever is more appropriate. Differs from fixed-point notation in that significant zeroes to the right of the decimal point are not included
  4677. // printf("%F\n", number); //FIXED.POINT NOTATION INFINITY AND NAN
  4678. // printf("%E\n", number); //standard form E+00
  4679. // printf("%G\n", number); ////Normal or exponent notation, uses uppercase letters, whichever is more appropriate. Differs from fixed-point notation in that significant zeroes to the right of the decimal point are not included
  4680. // printf("-\n");
  4681. //
  4682. // /*
  4683. // 1000000.100000
  4684. // 1.000000e+06
  4685. // 1e+06
  4686. // 1000000.100000
  4687. // 1.000000E+06
  4688. // 1E+06
  4689. // -
  4690. // */
  4691. //
  4692. // /*
  4693. // 100000.100000
  4694. // 1.000001e+05
  4695. // 100000
  4696. // 100000.100000
  4697. // 1.000001E+05
  4698. // 100000
  4699. // -
  4700. // */
  4701. // }
  4702. //}
  4703. //Valuable result: double does not wrap it goes to infinity. more of inf and nan support later. #define DBL_MAX 1.7976931348623158e+308 // max value #define DBL_MIN 2.2250738585072014e-308 // min positive value
  4704. //main()
  4705. //{
  4706. // long double number = 99999.1;
  4707. // while (number > 0)
  4708. // {
  4709. // number++;
  4710. // printf("%f\n", number); //fixed.point notation infinity and nan
  4711. // printf("%e\n", number); //standard form e+00
  4712. // printf("%g\n", number); //Normal or exponent notation, whichever is more appropriate. Differs from fixed-point notation in that significant zeroes to the right of the decimal point are not included
  4713. // printf("%F\n", number); //FIXED.POINT NOTATION INFINITY AND NAN
  4714. // printf("%E\n", number); //standard form E+00
  4715. // printf("%G\n", number); ////Normal or exponent notation, uses uppercase letters, whichever is more appropriate. Differs from fixed-point notation in that significant zeroes to the right of the decimal point are not included
  4716. // printf("-\n");
  4717. //
  4718. // /*
  4719. // 1000000.100000
  4720. // 1.000000e+06
  4721. // 1e+06
  4722. // 1000000.100000
  4723. // 1.000000E+06
  4724. // 1E+06
  4725. // -
  4726. // */
  4727. //
  4728. // /*
  4729. // 100000.100000
  4730. // 1.000001e+05
  4731. // 100000
  4732. // 100000.100000
  4733. // 1.000001E+05
  4734. // 100000
  4735. // -
  4736. // */
  4737. // //NOT DIFFERENT FROM DOUBLE
  4738. // }
  4739. //}
  4740. //Valuable result: long double does not wrap it goes to infinity, more on INF and NAN support later #define LDBL_MAX DBL_MAX // max value #define LDBL_MIN DBL_MIN // min normalized positive value
  4741. //Experiment: Changing the maximum and minimum of long double in <float.h>. Thought: 12/1/2019 Tested: not yet
  4742. //main()
  4743. //{
  4744. // float number = 999999.1;
  4745. // while (number > 0)
  4746. // {
  4747. // number++;
  4748. // printf("%f\n", number); //fixed.point notation infinity and nan
  4749. // printf("%e\n", number); //standard form e+00
  4750. // printf("%g\n", number); //Normal or exponent notation, whichever is more appropriate. Differs from fixed-point notation in that significant zeroes to the right of the decimal point are not included
  4751. // printf("%F\n", number); //FIXED.POINT NOTATION INFINITY AND NAN
  4752. // printf("%E\n", number); //standard form E+00
  4753. // printf("%G\n", number); ////Normal or exponent notation, uses uppercase letters, whichever is more appropriate. Differs from fixed-point notation in that significant zeroes to the right of the decimal point are not included
  4754. // printf("-\n");
  4755. //
  4756. // /*
  4757. // 1000000.125000
  4758. // 1.000000e+06
  4759. // 1e+06
  4760. // 1000000.125000
  4761. // 1.000000E+06
  4762. // 1E+06
  4763. // -
  4764. // */
  4765. //
  4766. // /*
  4767. // 100000.101563
  4768. // 1.000001e+05
  4769. // 100000
  4770. // 100000.101563
  4771. // 1.000001E+05
  4772. // 100000
  4773. // -
  4774. // */
  4775. // //DIFFERENT THAN DOUBLE AND LONG DOUBLE IN BOTH 99999.1 + 1 and 999999.1
  4776. // }
  4777. //}
  4778. //
  4779. //main()
  4780. //{
  4781. // float fnumber1 = 99999.1;
  4782. // double dnumber1 = 99999.1;
  4783. // long double ldnumber1 = 99999.1;
  4784. //
  4785. // float fnumber2 = 999999.1;
  4786. // double dnumber2 = 999999.1;
  4787. // long double ldnumber2 = 999999.1;
  4788. //
  4789. // int i = 0;
  4790. // printf("%18d+1%18d+1\n", 99999, 999999);
  4791. // while (i < 1) //Float
  4792. // {
  4793. // printf("Float\n");
  4794. // fnumber1++;
  4795. // fnumber2++;
  4796. // i++;
  4797. // printf("%20f%20f\n\n", fnumber1, fnumber2);
  4798. // printf("%20e%20e\n\n", fnumber1, fnumber2);
  4799. // printf("%20g%20g\n\n", fnumber1, fnumber2);
  4800. // printf("%20F%20F\n\n", fnumber1, fnumber2);
  4801. // printf("%20E%20E\n\n", fnumber1, fnumber2);
  4802. // printf("%20G%20G\n\n", fnumber1, fnumber2);
  4803. // printf("\n");
  4804. // }
  4805. // i = 0;
  4806. //
  4807. // while (i < 1) //Double
  4808. // {
  4809. // printf("Double\n");
  4810. // dnumber1++;
  4811. // dnumber2++;
  4812. // i++;
  4813. // printf("%20f%20f\n\n", dnumber1, dnumber2);
  4814. // printf("%20e%20e\n\n", dnumber1, dnumber2);
  4815. // printf("%20g%20g\n\n", dnumber1, dnumber2);
  4816. // printf("%20F%20F\n\n", dnumber1, dnumber2);
  4817. // printf("%20E%20E\n\n", dnumber1, dnumber2);
  4818. // printf("%20G%20G\n\n", dnumber1, dnumber2);
  4819. // printf("\n");
  4820. // }
  4821. // i = 0;
  4822. //
  4823. // while (i < 1) //Long Double
  4824. // {
  4825. // printf("Long Double\n");
  4826. // ldnumber1++;
  4827. // ldnumber2++;
  4828. // i++;
  4829. // printf("%20f%20f\n\n", ldnumber1, ldnumber2);
  4830. // printf("%20e%20e\n\n", ldnumber1, ldnumber2);
  4831. // printf("%20g%20g\n\n", ldnumber1, ldnumber2);
  4832. // printf("%20F%20F\n\n", ldnumber1, ldnumber2);
  4833. // printf("%20E%20E\n\n", ldnumber1, ldnumber2);
  4834. // printf("%20G%20G\n\n", ldnumber1, ldnumber2);
  4835. // printf("\n");
  4836. // }
  4837. //}
  4838. //The % operator determines what is printed and how it is printed while the variable is unaffected. The float data type output variance is because
  4839. //Valuable result: truncation occurs from double to float and long double to float
  4840. //Valuable result: exponent notation (%g and %G) begins at 1,000,000
  4841.  
  4842. //Valuable results: char 1 byte, short 2 bytes, int 4 bytes, long 4 bytes, float 4 bytes 6 decimal places, double 8 bytes 15 decimal places, long double 10 bytes 19 decimal places on other computers but it is 8 bytes 15 decimal places on my computer
  4843. //https://www.tutorialspoint.com/cprogramming/c_data_types.htm
  4844. //https://en.wikipedia.org/wiki/Printf_format_string
  4845. //Experiment: Changing the maximum and minimum of long double in <float.h>. Thought: 12/1/2019 Tested: not yet
  4846.  
  4847. //main()
  4848. //{
  4849. // printf("unsigned char: %u to %u\n", 0, UCHAR_MAX);
  4850. // printf("signed char: %d to %d\n", SCHAR_MIN, SCHAR_MAX);
  4851. // printf("char: %d to %d\n", CHAR_MIN, CHAR_MAX);
  4852. //
  4853. // printf("unsigned short int: %u to %u\n", 0, USHRT_MAX);
  4854. // printf("signed short int: %d to %d\n", SHRT_MIN, SHRT_MAX); //signed short
  4855. // printf("short: %d to %d\n", SHRT_MIN, SHRT_MAX); //short are the same
  4856. //
  4857. // printf("unsigned int: %u to %u\n", 0, UINT_MAX);
  4858. // printf("signed int: %d to %d\n", INT_MIN, INT_MAX); //signed int
  4859. // printf("int: %d to %d\n", INT_MIN, INT_MAX); //int are the same
  4860. //
  4861. // printf("unsigned long int: %u to %u\n", 0, ULONG_MAX);
  4862. // printf("signed long int: %d to %d\n", LONG_MIN, LONG_MAX); //signed long
  4863. // printf("long: %d to %d\n", LONG_MIN, LONG_MAX); //long are the same
  4864. //
  4865. // printf("unsigned long long int: %llu to %llu\n", 0, ULLONG_MAX);
  4866. // printf("signed long long int: %lld to %lld\n", LLONG_MIN, LLONG_MAX); //signed long long
  4867. // printf("long long: %lld to %lld\n", LLONG_MIN, LLONG_MAX); //long long are the same
  4868. //
  4869. // printf("float: %G to %G\n", FLT_MIN, FLT_MAX);
  4870. //
  4871. // printf("double: %G to %G\n", DBL_MIN, DBL_MAX);
  4872. //
  4873. // printf("long double: %G to %G\n", LDBL_MIN, LDBL_MAX);
  4874. //
  4875. // //limits.h includes number of bits, number of bytes in multibyte char, range for 8-bit/16-bit/32-bit/64-bit/128-bit values
  4876. // /*
  4877. // 1>C:\Users\funca\source\repos\C\P1\P1.c(4863,9): warning C4477: 'printf' : format string '%u' requires an argument of type 'unsigned int', but variadic argument 2 has type 'unsigned __int64'
  4878. // 1>C:\Users\funca\source\repos\C\P1\P1.c(4863,9): message : consider using '%llu' in the format string
  4879. // 1>C:\Users\funca\source\repos\C\P1\P1.c(4863,9): message : consider using '%I64u' in the format string
  4880. // 1>C:\Users\funca\source\repos\C\P1\P1.c(4864,9): warning C4477: 'printf' : format string '%d' requires an argument of type 'int', but variadic argument 1 has type '__int64'
  4881. // 1>C:\Users\funca\source\repos\C\P1\P1.c(4864,9): message : consider using '%lld' in the format string
  4882. // 1>C:\Users\funca\source\repos\C\P1\P1.c(4864,9): message : consider using '%I64d' in the format string
  4883. // 1>C:\Users\funca\source\repos\C\P1\P1.c(4864,9): warning C4477: 'printf' : format string '%d' requires an argument of type 'int', but variadic argument 2 has type '__int64'
  4884. // 1>C:\Users\funca\source\repos\C\P1\P1.c(4864,9): message : consider using '%lld' in the format string
  4885. // 1>C:\Users\funca\source\repos\C\P1\P1.c(4864,9): message : consider using '%I64d' in the format string
  4886. // 1>C:\Users\funca\source\repos\C\P1\P1.c(4865,9): warning C4477: 'printf' : format string '%d' requires an argument of type 'int', but variadic argument 1 has type '__int64'
  4887. // 1>C:\Users\funca\source\repos\C\P1\P1.c(4865,9): message : consider using '%lld' in the format string
  4888. // 1>C:\Users\funca\source\repos\C\P1\P1.c(4865,9): message : consider using '%I64d' in the format string
  4889. // 1>C:\Users\funca\source\repos\C\P1\P1.c(4865,9): warning C4477: 'printf' : format string '%d' requires an argument of type 'int', but variadic argument 2 has type '__int64'
  4890. // 1>C:\Users\funca\source\repos\C\P1\P1.c(4865,9): message : consider using '%lld' in the format string
  4891. // 1>C:\Users\funca\source\repos\C\P1\P1.c(4865,9): message : consider using '%I64d' in the format string
  4892. // */
  4893. //
  4894. // /*
  4895. // unsigned char: 0 to 255
  4896. // signed char: -128 to 127
  4897. // char: -128 to 127
  4898. // unsigned short int: 0 to 65535
  4899. // signed short int: -32768 to 32767
  4900. // short: -32768 to 32767
  4901. // unsigned int: 0 to 4294967295
  4902. // signed int: -2147483648 to 2147483647
  4903. // int: -2147483648 to 2147483647
  4904. // unsigned long int: 0 to 4294967295
  4905. // signed long int: -2147483648 to 2147483647
  4906. // long: -2147483648 to 2147483647
  4907. // unsigned long long int: 18446744069414584320 to 27887162523385855
  4908. // signed long long int: -9223372036854775808 to 9223372036854775807
  4909. // long long: -9223372036854775808 to 9223372036854775807
  4910. // float: 1.17549E-38 to 3.40282E+38
  4911. // double: 2.22507E-308 to 1.79769E+308
  4912. // long double: 2.22507E-308 to 1.79769E+308
  4913. // */
  4914. //}
  4915. //
  4916. //main()
  4917. //{
  4918. // int c;
  4919. // int lim;
  4920. // char line[40];
  4921. // int i = 0;
  4922. // for (lim = 0; lim < 100; lim++)
  4923. // {
  4924. // if ((c = getchar()) != '\n')
  4925. // {
  4926. // if (c != EOF)
  4927. // line[i++] = c;
  4928. // }
  4929. // }
  4930. //}
  4931.  
  4932. //int htoi(char array[])
  4933. //{
  4934. // int c;
  4935. // int i;
  4936. // int n;
  4937. // int pp;
  4938. // for (i = 0; isdigit(array[i]) || array[i] >= 'A' && array[i] <= 'Z' || array[i] >= 'a' && array[i] <= 'z'; i++)
  4939. // {
  4940. // if (isdigit(array[i]))
  4941. // pp = array[i] - '0';
  4942. // else if (array[i] == 'A' || array[i] == 'a')
  4943. // pp = 10;
  4944. // else if (array[i] == 'B' || array[i] == 'b')
  4945. // pp = 11;
  4946. // else if (array[i] == 'C' || array[i] == 'c')
  4947. // pp = 12;
  4948. // else if (array[i] == 'D' || array[i] == 'd')
  4949. // pp = 13;
  4950. // else if (array[i] == 'E' || array[i] == 'e')
  4951. // pp = 14;
  4952. // else if (array[i] == 'F' || array[i] == 'f')
  4953. // pp = 15;
  4954. // n = n * 10 + pp;
  4955. // if (i == 0 && array[i] == '0')
  4956. // {
  4957. // i = 3;
  4958. // n = 0;
  4959. // }
  4960. // return n;
  4961. // }
  4962. //}
  4963.  
  4964. //void squeezedelete(char s1[], char s2[])
  4965. //{
  4966. // int i = 0;
  4967. // int j;
  4968. // int k = 0;
  4969. // while (s1[i] != '\0')
  4970. // {
  4971. // j = 0;
  4972. // while (s2[j] != '\0' && s1[i] != s2[j])
  4973. // {
  4974. // if (s2[j+1] == '\0')
  4975. // {
  4976. // s1[k++] = s1[i];
  4977. // }
  4978. // j++;
  4979. // }
  4980. // i++;
  4981. // }
  4982. //}
  4983.  
  4984. //void firstcommoncharacter(char s1[], char s2[])
  4985. //{
  4986. // int i;
  4987. // int j;
  4988. // int fcci = 0;
  4989. //
  4990. // while (s1[i] != '\0')
  4991. // {
  4992. // j = 0;
  4993. // while (s2[j++] != '\0')
  4994. // {
  4995. // if (s1[i] == s2[j])
  4996. // {
  4997. // return ++fcci;
  4998. // }
  4999. // fcci++;
  5000. // }
  5001. // if (s1[i + 1] == '\0')
  5002. // return -1;
  5003. // i++;
  5004. // }
  5005. //}
  5006.  
  5007. //unsigned setbits(unsigned x, int p, int n, unsigned y) //signed instead of unsigned for sign bit sign extension p.50
  5008. //{
  5009. // return ((x >> (p + 1 - n)) & (y & ~(~0 << n));
  5010. //}
  5011.  
  5012. //unsigned invert(unsigned x, int p, int n) //signed instead of unsigned for sign bit sign extension p.50
  5013. //{
  5014. // return x ^ ((~0 << p + 1 - n) >> n - 1); //arithmetic right shift, sign extension vital
  5015. //}
  5016.  
  5017. //unsigned rightrot(unsigned x, int n) //signed instead of unsigned for sign bit sign extension p.50
  5018. //{
  5019. // unsigned x2 = x;
  5020. // int size = bitsize(x); //function bitsize counts the number of bits in x. Example x = 0000 returns 4.
  5021. // return (x >> n) | ((~0 << size - 1) & (x2 << size - n));
  5022. //}
  5023.  
  5024. //unsigned bitcount_Faster(unsigned x)
  5025. //{
  5026. // return ~(x - 1);
  5027. //}
  5028.  
  5029. //void lower(char array[])
  5030. //{
  5031. // int i = 0;
  5032. // while (array[i] != '\0')
  5033. // {
  5034. // array[i] = (array[i] >= 'A' || array[i] <= 'Z') ? array[i] + 'a' - 'A' : array[i];
  5035. // i++;
  5036. // }
  5037. //}
  5038.  
  5039. //int binsearch(int x, char array[], int bottom, int top)
  5040. //{
  5041. // int low = bottom;
  5042. // int high = top - 1;
  5043. // int middle = (high + low) / 2;
  5044. //
  5045. // while (x != array[middle] && (high + middle) / 2 != middle && (low + middle) / 2 != middle)
  5046. // {
  5047. // if (x > array[middle])
  5048. // middle = (high + middle) / 2;
  5049. // else
  5050. // middle = (low + middle) / 2;
  5051. // }
  5052. // if (x == array[middle])
  5053. // return middle;
  5054. // else
  5055. // return -1;
  5056. //} //did not run them next to eachother was not interested in that moment
  5057.  
  5058. //void escape(char s[], char t[])
  5059. //{
  5060. // int i = 0;
  5061. // int j = 0;
  5062. // while (s[i] != '\0')
  5063. // {
  5064. // switch (s[i])
  5065. // {
  5066. // case '\n':
  5067. // t[j] = '\\';
  5068. // j++;
  5069. // t[j] = 'n';
  5070. // i++;
  5071. // break;
  5072. // case '\t':
  5073. // t[j] = '\\';
  5074. // j++;
  5075. // t[j] = 't';
  5076. // i++;
  5077. // break;
  5078. // default:
  5079. // t[j] = s[i];
  5080. // j++;
  5081. // i++;
  5082. // break;
  5083. // }
  5084. // }
  5085. //}
  5086.  
  5087. //void escapereversed(char s[], char t[])
  5088. //{
  5089. // int i = 0;
  5090. // int j = 0;
  5091. // while (s[i] != '\0')
  5092. // {
  5093. // switch (s[i])
  5094. // {
  5095. // case ('\\'):
  5096. // if (s[i + 1] == 'n')
  5097. // {
  5098. // t[j] = '\n';
  5099. // j++;
  5100. // i++;
  5101. // break;
  5102. // }
  5103. // else if (s[i + 1] == 't')
  5104. // {
  5105. // t[j] = '\t';
  5106. // j++;
  5107. // i++;
  5108. // break;
  5109. // }
  5110. // else
  5111. // {
  5112. // t[j] = s[i];
  5113. // j++;
  5114. // i++;
  5115. // break;
  5116. // }
  5117. // default:
  5118. // t[j] = s[i];
  5119. // j++;
  5120. // i++;
  5121. // break;
  5122. // }
  5123. // }
  5124. //}
  5125.  
  5126. //https://www.youtube.com/watch?v=qzXAVXddcPU
  5127.  
  5128. //void expand(char s1[], char s2[]);
  5129. //
  5130. //main()
  5131. //{
  5132. // int c;
  5133. // int i = 0;
  5134. // char s1[MAXARRAYSIZE];
  5135. // char s2[MAXARRAYSIZE];
  5136. // while ((c = getchar()) != EOF)
  5137. // s1[i++] = c;
  5138. // s1[i] = '\0';
  5139. // expand(s1, s2);
  5140. // printf("%s", s2);
  5141. //}
  5142. //
  5143. //void expand(char s1[], char s2[])
  5144. //{
  5145. // int INALETTEREXPANSION = NO;
  5146. // int INANUMBEREXPANSION = NO;
  5147. // int i = 0;
  5148. // int k;
  5149. // int j = 0;
  5150. // int nc = 0;
  5151. // int valk;
  5152. // int vali;
  5153. // int inc;
  5154. // while (s1[i] != '\0' && s1[i] != EOF)
  5155. // {
  5156. // switch (s1[i])
  5157. // {
  5158. // case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
  5159. // case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
  5160. // if (!INALETTEREXPANSION)
  5161. // {
  5162. // s2[j++] = s1[i];
  5163. // INALETTEREXPANSION = YES;
  5164. // }
  5165. // k = i + 1;
  5166. // nc = 1;
  5167. // while (!isalnum(s1[k]) && s1[k] != '-' && s1[k] != '\0' && s1[k] != EOF)
  5168. // nc++, k++;
  5169. // if (isdigit(s1[k]))
  5170. // {
  5171. // INALETTEREXPANSION = NO;
  5172. // i++;
  5173. // }
  5174. // else if (s1[k] == '-')
  5175. // {
  5176. // nc++, k++;
  5177. // while (!isalnum(s1[k]) && s1[k] != '\0' && s1[k] != EOF)
  5178. // nc++, k++;
  5179. // if (isalpha(s1[k]) && s1[k] > s1[i])
  5180. // {
  5181. // valk = s1[k];
  5182. // vali = s1[i];
  5183. // inc = 1;
  5184. // while (valk-- > vali)
  5185. // {
  5186. // s2[j++] = s1[i] + inc++;
  5187. // }
  5188. // i += nc;
  5189. // INALETTEREXPANSION = YES;
  5190. // }
  5191. // else if (isalpha(s1[k]) && s1[k] < s1[i])
  5192. // {
  5193. // valk = s1[k];
  5194. // vali = s1[i];
  5195. // inc = 1;
  5196. // while (valk++ < vali)
  5197. // {
  5198. // s2[j++] = s1[i] - inc++;
  5199. // }
  5200. // i += nc;
  5201. // INALETTEREXPANSION = YES;
  5202. // }
  5203. // else if (isalpha(s1[k]) && s1[k] == s1[i])
  5204. // {
  5205. // s2[j++] = s1[i];
  5206. // i += nc;
  5207. // }
  5208. // else
  5209. // {
  5210. // s2[j++] = '-';
  5211. // i += nc;
  5212. // INALETTEREXPANSION = NO;
  5213. // }
  5214. // }
  5215. // else if (isalpha(s1[k]))
  5216. // {
  5217. // INALETTEREXPANSION = NO;
  5218. // i += nc;
  5219. // }
  5220. // else
  5221. // i++;
  5222. // break;
  5223. // case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
  5224. // if (!INANUMBEREXPANSION)
  5225. // {
  5226. // s2[j++] = s1[i];
  5227. // INANUMBEREXPANSION = YES;
  5228. // }
  5229. // k = i + 1;
  5230. // nc = 1;
  5231. // while (!isalnum(s1[k]) && s1[k] != '-' && s1[k] != '\0' && s1[k] != EOF)
  5232. // nc++, k++;
  5233. // if (isalpha(s1[k]))
  5234. // {
  5235. // INANUMBEREXPANSION = NO;
  5236. // i++;
  5237. // }
  5238. // else if (s1[k] == '-')
  5239. // {
  5240. // nc++, k++;
  5241. // while (!isalnum(s1[k]) && s1[k] != '\0' && s1[k] != EOF)
  5242. // nc++, k++;
  5243. // if (isdigit(s1[k]) && s1[k] > s1[i])
  5244. // {
  5245. // valk = s1[k];
  5246. // vali = s1[i];
  5247. // inc = 1;
  5248. // while (valk-- > vali)
  5249. // {
  5250. // s2[j++] = s1[i] + inc++;
  5251. // }
  5252. // i += nc;
  5253. // INANUMBEREXPANSION = YES;
  5254. // }
  5255. // else if (isdigit(s1[k]) && s1[k] < s1[i])
  5256. // {
  5257. // valk = s1[k];
  5258. // vali = s1[i];
  5259. // inc = 1;
  5260. // while (valk++ < vali)
  5261. // {
  5262. // s2[j++] = s1[i] - inc++;
  5263. // }
  5264. // i += nc;
  5265. // INANUMBEREXPANSION = YES;
  5266. // }
  5267. // else if (isdigit(s1[k]) && s1[k] == s1[i])
  5268. // {
  5269. // s2[j++] = s1[i];
  5270. // i += nc;
  5271. // }
  5272. // else
  5273. // {
  5274. // s2[j++] = '-';
  5275. // i += nc;
  5276. // INANUMBEREXPANSION = NO;
  5277. // }
  5278. // }
  5279. // else if (isalpha(s1[k]))
  5280. // {
  5281. // INANUMBEREXPANSION = NO;
  5282. // i += nc;
  5283. // }
  5284. // else
  5285. // i++;
  5286. // break;
  5287. // default:
  5288. // s2[j++] = s1[i++];
  5289. // break;
  5290. // }
  5291. // }
  5292. // s2[j] = '\0';
  5293. //}
  5294.  
  5295. //void reverse(char s[])
  5296. //{
  5297. // char temp[MAXARRAYSIZE];
  5298. // int i = 0;
  5299. // int j = 0;
  5300. // int pointofreverse = 0;
  5301. //
  5302. // while (s[i] != '\0')
  5303. // {
  5304. // while (s[i] != '\n' && s[i] != '\0')
  5305. // {
  5306. // i++;
  5307. // }
  5308. // pointofreverse = i - 1;
  5309. // while (j < i)
  5310. // {
  5311. // temp[j++] = s[pointofreverse--];
  5312. // }
  5313. // temp[j] = s[i++];
  5314. // }
  5315. // temp[j] = '\0';
  5316. // s = temp; //new reverse on 5373
  5317. //}
  5318. //The problem is that, if n is the largest negative number, when you do n = -n you obtain 0, bacause you cannot represent a positive number that big.
  5319. //A solution can be to hold the positive number in a long integer.
  5320. //Learned ints are stored using binary number representation systems 127 = 01111111 -128 = 10000000. char is a int (56) representing a character 'A
  5321. //void itoa(int n, char s[])
  5322. //{
  5323. // int i;
  5324. // int sign;
  5325. // long long int holdthepositivenumber;
  5326. // if ((sign = n) < 0)
  5327. // holdthepositivenumber = -n; //n = -n;
  5328. // i = 0;
  5329. // do {
  5330. // s[i++] = n % 10 + '0';
  5331. // } while ((n /= 10) > 0);
  5332. // if (sign < 0)
  5333. // s[i++] = '-';
  5334. // s[i] = '\0';
  5335. // reverse(s);
  5336. //}
  5337. //void reverse(char s[]);
  5338. //void itob(int n, char s[], int b);
  5339. //int atoi(char s[]);
  5340. //main()
  5341. //{
  5342. // int c;
  5343. // char anumber[MAXARRAYSIZE];
  5344. // int number;
  5345. // int i = 0;
  5346. // int base;
  5347. // while ((c = getchar()) != '\n')
  5348. // anumber[i++] = c;
  5349. // anumber[i] = '\0', printf("%s\n", anumber);
  5350. // number = atoi(anumber), printf("%d\n", number);
  5351. // i = 0, anumber[0] = '\0';
  5352. // while ((c = getchar()) != '\n')
  5353. // anumber[i++] = c;
  5354. // anumber[i] = '\0', printf("%s\n", anumber);
  5355. // base = atoi(anumber), printf("%d\n", base);
  5356. // anumber[0] = '\0', itob(number, anumber, base), printf("%s\n", anumber);
  5357. //}
  5358. //void itob(int n, char s[], int b)
  5359. //{
  5360. // int i = 0;
  5361. // int nrc;
  5362. // while (n > 0)
  5363. // {
  5364. // if ((nrc = n % b) >= 10)
  5365. // s[i++] = (char) (nrc + 55);
  5366. // else
  5367. // s[i++] = (char) (nrc + '0');
  5368. // n /= b;
  5369. // }
  5370. // s[i] = '\0';
  5371. // reverse(s);
  5372. //}
  5373. //void reverse(char s[])
  5374. //{
  5375. // char temp[MAXARRAYSIZE];
  5376. // int i = 0;
  5377. // int j = 0;
  5378. // int pointofreverse = 0;
  5379. // while (s[i] != '\0' && s[i] != EOF)
  5380. // {
  5381. // while (s[i] != '\n' && s[i] != '\0' && s[i] != EOF)
  5382. // i++;
  5383. // pointofreverse = i - 1;
  5384. // while (j < i)
  5385. // temp[j++] = s[pointofreverse--];
  5386. // temp[j++] = s[i];
  5387. // if (s[i] != '\0')
  5388. // i++;
  5389. // }
  5390. // temp[j] = '\0';
  5391. // i = 0;
  5392. // while ((s[i] = temp[i]) != '\0')
  5393. // i++;
  5394. //}
  5395. //int atoi(char s[])
  5396. //{
  5397. // int sign;
  5398. // int i = 0;
  5399. // int n = 0;
  5400. // if (s[i] == '-')
  5401. // {
  5402. // sign = YES;
  5403. // i++;
  5404. // }
  5405. // while (s[i] != '\0')
  5406. // n = n * 10 + (s[i++] - '0');
  5407. // return n;
  5408. //}
  5409. //void reverse(char s[]);
  5410. //main()
  5411. //{
  5412. // int c;
  5413. // int i = 0;
  5414. // char array[MAXARRAYSIZE];
  5415. // while ((c = getchar()) != '!')
  5416. // array[i++] = c;
  5417. // array[i] = '\0';
  5418. // reverse(array);
  5419. // printf("%s", array);
  5420. //}
  5421. //void reverse(char s[])
  5422. //{
  5423. // char temp[MAXARRAYSIZE];
  5424. // int i = 0;
  5425. // int j = 0;
  5426. // int pointofreverse = 0;
  5427. // while (s[i] != '\0' && s[i] != EOF)
  5428. // {
  5429. // while (s[i] != '\n' && s[i] != '\0' && s[i] != EOF)
  5430. // i++;
  5431. // pointofreverse = i - 1;
  5432. // while (j < i)
  5433. // temp[j++] = s[pointofreverse--];
  5434. // temp[j++] = s[i];
  5435. // if (s[i] != '\0')
  5436. // i++;
  5437. // }
  5438. // temp[j] = '\0';
  5439. // i = 0;
  5440. // while ((s[i] = temp[i]) != '\0')
  5441. // i++;
  5442. //}
  5443.  
  5444. //void itoawithpadding(int n, char s[], int padding)
  5445. //{
  5446. // long long int carefulconversion;
  5447. // int sign = NO;
  5448. // int i = 0;
  5449. // if (n < 0)
  5450. // {
  5451. // n = -n;
  5452. // sign = YES;
  5453. // padding = padding - 1;
  5454. // }
  5455. // while (n > 0)
  5456. // {
  5457. // s[i++] = n % 10;
  5458. // n /= 10;
  5459. // padding--;
  5460. // }
  5461. // s[i++] = '-';
  5462. // while (padding-- > 0)
  5463. // {
  5464. // s[i++] = ' ';
  5465. // }
  5466. // s[i] = '\0'; //this one character more than the minimum width padding
  5467. // reverse(s);
  5468. //}
  5469.  
  5470. //int getline(char line[], int max);
  5471. //int strindex(char source[], char searchfor[]);
  5472. //
  5473. //char pattern[] = "ould";
  5474. //
  5475. //main()
  5476. //{
  5477. // char line[MAXARRAYSIZE];
  5478. // int found = 0;
  5479. //
  5480. // while (getline(line, MAXARRAYSIZE) > 0)
  5481. // if (strindex(line, pattern) >= 0) {
  5482. // printf("%s", line);
  5483. // found++;
  5484. // }
  5485. // return found;
  5486. //}
  5487. //int getline(char s[], int lim)
  5488. //{
  5489. // int c;
  5490. // int i = 0;
  5491. // while (--lim > 0 && (c = getchar()) != EOF && c != '\n')
  5492. // s[i++] = c;
  5493. // if (c == '\n')
  5494. // s[i++] = c;
  5495. // s[i] = '\0';
  5496. // return i;
  5497. //}
  5498. //int strindex(char s[], char t[])
  5499. //{
  5500. // int i, j, k;
  5501. //
  5502. // for (i = 0; s[i] != '\0'; i++) {
  5503. // for (j = i, k = 0; t[k]!= '\0' && s[j] == t[k]; j++, k++)
  5504. // ;
  5505. // if (k > 0 && t[k] == '\0')
  5506. // return i;
  5507. // }
  5508. // return -1;
  5509. //}
  5510. //int getline(char line[], int max);
  5511. //int strrindex(char source[], char searchfor[]);
  5512. //
  5513. //char pattern[] = "ould";
  5514. //
  5515. //main()
  5516. //{
  5517. // char line[MAXARRAYSIZE];
  5518. // int found = 0;
  5519. // int index = 0;
  5520. // int linenumber = 0;
  5521. //
  5522. // while (getline(line, MAXARRAYSIZE) > 0)
  5523. // if ((index = strrindex(line, pattern)) >= 0) {
  5524. // printf("The rightmost occurance of the pattern on line %d occurs at index %d", index);
  5525. // found++;
  5526. // linenumber++;
  5527. // }
  5528. // else
  5529. // printf("The line %d did not contain the pattern\n", linenumber++);
  5530. // return found;
  5531. //}
  5532. //int getline(char s[], int lim)
  5533. //{
  5534. // int c;
  5535. // int i = 0;
  5536. // while (--lim > 0 && (c = getchar()) != EOF && c != '\n')
  5537. // s[i++] = c;
  5538. // if (c == '\n')
  5539. // s[i++] = c;
  5540. // s[i] = '\0';
  5541. // return i;
  5542. //}
  5543. //int strrindex(char s[], char t[])
  5544. //{
  5545. // int i, j, k, index;
  5546. // int index = 0;
  5547. //
  5548. // for (i = 0; s[i] != '\0'; i++) {
  5549. // for (j = i, k = 0; t[k] != '\0' && s[j] == t[k]; j++, k++)
  5550. // ;
  5551. // if (k > 0 && t[k] == '\0')
  5552. // {
  5553. // index = i;
  5554. // }
  5555. // }
  5556. // if (index)
  5557. // return index;
  5558. // else
  5559. // return -1;
  5560. //}
  5561.  
  5562. //double atof(char s[])
  5563. //{
  5564. // int i = 0;
  5565. // int sign = 1;
  5566. // int val = 0;
  5567. // int power = 1;
  5568. // int e = 0;
  5569. // double exp = 0;
  5570. // if (s[i] == '-')
  5571. // {
  5572. // sign = -1;
  5573. // i++;
  5574. // }
  5575. // else if (s[i] == '+')
  5576. // i++;
  5577. // while (isdigit(s[i]))
  5578. // val = val * 10 + (s[i++] - '0');
  5579. // if (s[i] == '.')
  5580. // {
  5581. // i++;
  5582. // while (isdigit(s[i]))
  5583. // {
  5584. // val = val * 10 + (s[i++] - '0');
  5585. // power *= 10;
  5586. // }
  5587. // }
  5588. // val = sign * val / power;
  5589. // if (s[i] == 'e' || s[i] == 'E')
  5590. // {
  5591. // i++;
  5592. // if (s[i] == '-')
  5593. // {
  5594. // i++;
  5595. // while (isdigit(s[i])) //atoi
  5596. // e = e * 10 + (s[i] - '0');
  5597. // while (e-- > 0)
  5598. // val /= 10;
  5599. // return val;
  5600. // }
  5601. // else if (s[i] == '+')
  5602. // {
  5603. // i++;
  5604. // while (isdigit(s[i])) //atoi
  5605. // e = e * 10 + (s[i] - '0');
  5606. // while (e-- > 0)
  5607. // val *= 10;
  5608. // return val;
  5609. // }
  5610. // }
  5611. // else
  5612. // return val;
  5613. //}
  5614.  
  5615. //#define NUMBER 1
  5616. //
  5617. //int getop(char []);
  5618. //void push(double);
  5619. //double pop(void);
  5620. //int getch(void);
  5621. //void ungetch(int);
  5622. //double atof(char[]);
  5623. //
  5624. //char operator_or_error_overread[MAXARRAYSIZE];
  5625. //int index_error = 0;
  5626. //
  5627. //int index = 0;
  5628. //double values[MAXARRAYSIZE];
  5629. //
  5630. //char pushbackentirestring[MAXARRAYSIZE];
  5631. //int j = 0;
  5632. //int array_index = 0;
  5633. //
  5634. //char number[MAXARRAYSIZE];
  5635. //int index_number = 0;
  5636. //int beginningofsubarray = 0;
  5637. //
  5638. //main() //q, w, e for sin cos pow
  5639. //{
  5640. // int operator;
  5641. // double operator2;
  5642. // double temp;
  5643. // double temp2;
  5644. // int pushbackentirestringontoinput = 0;
  5645. // char op[MAXARRAYSIZE];
  5646. //
  5647. // while ((operator = getop(op)) != EOF)
  5648. // {
  5649. // switch (operator) {
  5650. // case NUMBER:
  5651. // push(atof(op));
  5652. // break;
  5653. // case '+':
  5654. // push(pop() + pop());
  5655. // break;
  5656. // case '*':
  5657. // push(pop() * pop());
  5658. // break;
  5659. // case '-':
  5660. // operator2 = pop();
  5661. // push(pop() - operator2);
  5662. // break;
  5663. // case '/':
  5664. // operator2 = pop();
  5665. // if (operator2 != 0.0)
  5666. // push(pop() / operator2);
  5667. // else
  5668. // printf("Error: Operator 2 is 0. Cannot divide by 0.\n");
  5669. // break;
  5670. // case '%':
  5671. // operator2 = pop();
  5672. // if (operator2 != 0)
  5673. // push((int) pop() % (int) operator2);
  5674. // else
  5675. // printf("Error: Operator 2 is 0. Cannot divide by 0.\n");
  5676. // break;
  5677. // case 'p':
  5678. // temp = pop();
  5679. // push(temp);
  5680. // printf("%f", temp);
  5681. // break;
  5682. // case 'd':
  5683. // temp = pop();
  5684. // push(temp);
  5685. // push(temp);
  5686. // break;
  5687. // case 's':
  5688. // temp = pop();
  5689. // temp2 = pop();
  5690. // push(temp);
  5691. // push(temp2);
  5692. // break;
  5693. // case 'c':
  5694. // //while(isdigit(pop()));
  5695. // values[0] = '\0';
  5696. // index = 0;
  5697. // break;
  5698. // case 'q':
  5699. // push(sin(pop()));
  5700. // break;
  5701. // case 'w':
  5702. // push(cos(pop()));
  5703. // break;
  5704. // case 'e':
  5705. // operator2 = pop();
  5706. // push(pow(pop(), operator2));
  5707. // break;
  5708. // case 'u':
  5709. // pushbackentirestringontoinput = 1;
  5710. // goto ungets;
  5711. // break;
  5712. // case '\n':
  5713. // printf("\t%.8f\n", pop());
  5714. // break;
  5715. // default:
  5716. // printf("Error: The program read a character using getchar() that was not a digit or a character with a switch case defined. The character is %s.\n", op);
  5717. // break;
  5718. // }
  5719. // }
  5720. // ungets:
  5721. // while (pushbackentirestring[j] != '\0')
  5722. // {
  5723. // while ((operator = getop2(pushbackentirestring)) != EOF)
  5724. // {
  5725. // switch (operator) {
  5726. // case NUMBER:
  5727. // push(atof(op));
  5728. // break;
  5729. // case '+':
  5730. // push(pop() + pop());
  5731. // break;
  5732. // case '*':
  5733. // push(pop() * pop());
  5734. // break;
  5735. // case '-':
  5736. // operator2 = pop();
  5737. // push(pop() - operator2);
  5738. // break;
  5739. // case '/':
  5740. // operator2 = pop();
  5741. // if (operator2 != 0.0)
  5742. // push(pop() / operator2);
  5743. // else
  5744. // printf("Error: Operator 2 is 0. Cannot divide by 0.\n");
  5745. // break;
  5746. // case '%':
  5747. // operator2 = pop();
  5748. // if (operator2 != 0)
  5749. // push((int)pop() % (int)operator2);
  5750. // else
  5751. // printf("Error: Operator 2 is 0. Cannot divide by 0.\n");
  5752. // break;
  5753. // case 'p':
  5754. // temp = pop();
  5755. // push(temp);
  5756. // printf("%f", temp);
  5757. // break;
  5758. // case 'd':
  5759. // temp = pop();
  5760. // push(temp);
  5761. // push(temp);
  5762. // break;
  5763. // case 's':
  5764. // temp = pop();
  5765. // temp2 = pop();
  5766. // push(temp);
  5767. // push(temp2);
  5768. // break;
  5769. // case 'c':
  5770. // //while(isdigit(pop()));
  5771. // values[0] = '\0';
  5772. // index = 0;
  5773. // break;
  5774. // case 'q':
  5775. // push(sin(pop()));
  5776. // break;
  5777. // case 'w':
  5778. // push(cos(pop()));
  5779. // break;
  5780. // case 'e':
  5781. // operator2 = pop();
  5782. // push(pow(pop(), operator2));
  5783. // break;
  5784. // case '\n':
  5785. // printf("\t%.8f\n", pop());
  5786. // break;
  5787. // default:
  5788. // printf("Error: The program read a character using getchar() that was not a digit or a character with a switch case defined. The character is %s.\n", op);
  5789. // break;
  5790. // }
  5791. // }
  5792. // }
  5793. //}
  5794. //
  5795. //void push(double OperandValue)
  5796. //{
  5797. // if (index < MAXARRAYSIZE)
  5798. // values[index++] = OperandValue;
  5799. // else
  5800. // printf("Error: Stack full. Cannot push operand value %g.\n", OperandValue);
  5801. //}
  5802. //
  5803. //double pop(void)
  5804. //{
  5805. // if (index > 0)
  5806. // return values[--index];
  5807. // else
  5808. // {
  5809. // printf("Error: There are 0 operands stored in the stack containing numbers.\n");
  5810. // return 0.0;
  5811. // }
  5812. //}
  5813. //
  5814. //int getop(char s[])
  5815. //{
  5816. // int c;
  5817. // int d;
  5818. // int i = 0;
  5819. //
  5820. // while ((s[i] = c = getch()) == ' ' || c == '\t') //skips white space by overwriting c into s[0] until an operand, operator, or error is read using getch() which reads an operand or error from getchar() overreading past a number onto an operator 123.456+.
  5821. // ;
  5822. // s[i++] = '\0';
  5823. // if (!isdigit(c) && c != '.' && c != '-')
  5824. // return c;
  5825. // if (c == '-' && !isdigit(d = getch()))
  5826. // {
  5827. // ungetch(d);
  5828. // return c;
  5829. // }
  5830. // else if (c == '-')
  5831. // s[i++] = '-';
  5832. // if (isdigit(c))
  5833. // while (isdigit(s[i++] = c = getch()))
  5834. // ;
  5835. // if (c == '.')
  5836. // {
  5837. // s[i++] = c;
  5838. // while (isdigit(s[i++] = c = getch()))
  5839. // ;
  5840. // }
  5841. // s[i] = '\0';
  5842. // if (c != EOF)
  5843. // ungetch(c);
  5844. //
  5845. // return NUMBER;
  5846. //}
  5847. //
  5848. //int getop2(char s[])
  5849. //{
  5850. // while (s[array_index] == ' ' || s[array_index] == '\t')
  5851. // i++;
  5852. // if (!isdigit(s[i]) && s[i] != '.' && s[i] != '-')
  5853. // return s[i];
  5854. // if (s[i] == '-' && !isdigit(s[i + 1]))
  5855. // return s[i];
  5856. // else if (s[i] == '-')
  5857. // {
  5858. // beginningofsubarray = i;
  5859. // number[index_number++] = '-';
  5860. // i++;
  5861. // }
  5862. // if (isdigit(s[i]))
  5863. // while (isdigit(s[i]))
  5864. // number[index_number++] = s[i++];
  5865. // if (s[i] == '.')
  5866. // {
  5867. // number[index_number++] = s[i];
  5868. // while (isdigit(s[i]))
  5869. // number[index_number++] = s[i++];
  5870. // }
  5871. // s[i] = '\0';
  5872. // if (s[i] != EOF)
  5873. // i--;
  5874. //
  5875. // return NUMBER;
  5876. //}
  5877. //
  5878. //int getch(void)
  5879. //{
  5880. // return (index_error > 0) ? operator_or_error_overread[--index_error] : getchar();
  5881. //}
  5882. //
  5883. //void ungetch(int operator_or_error) //stores overread operators or errors in a stack operator_or_error_overread[MAXARRAYSIZE]
  5884. //{
  5885. // if (index_error >= MAXARRAYSIZE)
  5886. // printf("Error: Stack full. Cannot push character %c.\n");
  5887. // else
  5888. // operator_or_error_overread[index_error++] = operator_or_error;
  5889. //}
  5890. //
  5891. //double atof(char s[])
  5892. //{
  5893. // int i = 0;
  5894. // int sign = 1;
  5895. // int val = 0;
  5896. // int power = 1;
  5897. // int e = 0;
  5898. // double exp = 0;
  5899. // if (s[i] == '-')
  5900. // {
  5901. // sign = -1;
  5902. // i++;
  5903. // }
  5904. // else if (s[i] == '+')
  5905. // i++;
  5906. // while (isdigit(s[i]))
  5907. // val = val * 10 + (s[i++] - '0');
  5908. // if (s[i] == '.')
  5909. // {
  5910. // i++;
  5911. // while (isdigit(s[i]))
  5912. // {
  5913. // val = val * 10 + (s[i++] - '0');
  5914. // power *= 10;
  5915. // }
  5916. // }
  5917. // val = sign * val / power;
  5918. // if (s[i] == 'e' || s[i] == 'E')
  5919. // {
  5920. // i++;
  5921. // if (s[i] == '-')
  5922. // {
  5923. // i++;
  5924. // while (isdigit(s[i])) //atoi
  5925. // e = e * 10 + (s[i] - '0');
  5926. // while (e-- > 0)
  5927. // val /= 10;
  5928. // return val;
  5929. // }
  5930. // else if (s[i] == '+')
  5931. // {
  5932. // i++;
  5933. // while (isdigit(s[i])) //atoi
  5934. // e = e * 10 + (s[i] - '0');
  5935. // while (e-- > 0)
  5936. // val *= 10;
  5937. // return val;
  5938. // }
  5939. // }
  5940. // else
  5941. // return val;
  5942. //}
  5943.  
  5944.  
  5945.  
  5946. //#define NUMBER 1
  5947. //
  5948. //int getop(char[]);
  5949. //void push(double);
  5950. //double pop(void);
  5951. //int getchx(void);
  5952. //void ungetchx(int);
  5953. //double atofx(char[]);
  5954. //int getline(char[], int);
  5955. //
  5956. //char operator_or_error_overread[MAXARRAYSIZE];
  5957. //int index_error = 0;
  5958. //
  5959. //int index = 0;
  5960. //double values[MAXARRAYSIZE];
  5961. //
  5962. //char ungets_string[MAXARRAYSIZE];
  5963. //int ungets_index = 0;
  5964. //
  5965. ////store a duplicate of every input into ungets
  5966. //
  5967. //main() //q, w, e for sin cos pow //print //most recently printed value
  5968. //{
  5969. // int linelength = 0;
  5970. // char getlinearray[MAXARRAYSIZE];
  5971. // int operator;
  5972. // double operator2;
  5973. // double temp;
  5974. // double temp2;
  5975. // char op[MAXARRAYSIZE];
  5976. //
  5977. // double a = 0;
  5978. // int a_def = NO;
  5979. // double b = 0;
  5980. // int b_def = NO;
  5981. // double x = 0;
  5982. // int x_def = NO;
  5983. // double y = 0;
  5984. // int y_def = NO; //must be double to safely store double values from pop()
  5985. // int undef = 0;
  5986. //
  5987. // double mrp = 0.0; //must be able to handle floating-point values
  5988. //
  5989. // while ((linelength = getline(getlinearray, MAXARRAYSIZE)) > 0)
  5990. // {
  5991. // while (linelength >= 1)
  5992. // {
  5993. // operator_or_error_overread[index_error++] = getlinearray[linelength-- - 1];
  5994. // operator_or_error_overread[index_error] = '\0';
  5995. // }
  5996. // getlinearray[0] = '\0';
  5997. // while ((operator = getop(op)) != EOF)
  5998. // {
  5999. // switch (operator) {
  6000. // case '0':
  6001. // goto terminate;
  6002. // break;
  6003. // case 'a':
  6004. // if (a_def == NO)
  6005. // {
  6006. // if (index > 0)
  6007. // a = pop(), a_def = YES;
  6008. // else
  6009. // a = 0;
  6010. // }
  6011. // else
  6012. // push(a);
  6013. // break;
  6014. // case 'b':
  6015. // if (b_def == NO)
  6016. // b = pop(), b_def = YES;
  6017. // else
  6018. // push(b);
  6019. // break;
  6020. // case 'x':
  6021. // if (x_def == NO)
  6022. // x = pop(), x_def = YES;
  6023. // else
  6024. // push(a);
  6025. // break;
  6026. // case 'y':
  6027. // if (y_def == NO)
  6028. // y = pop(), y_def = YES;
  6029. // else
  6030. // push(a);
  6031. // break;
  6032. // case 'z': //assuming appropriate usage
  6033. // undef = getchar();
  6034. // switch (undef) {
  6035. // case 'a':
  6036. // a_def = NO;
  6037. // break;
  6038. // case 'b':
  6039. // b_def = NO;
  6040. // break;
  6041. // case 'x':
  6042. // x_def = NO;
  6043. // break;
  6044. // case 'y':
  6045. // y_def = NO;
  6046. // break;
  6047. // default: printf("Error: The character after z is supposed to be a variable. The variable are a, b, x, and y. The correct syntax to undefine a variable is za, zb, zx, and zy.\n");
  6048. // break;
  6049. // }
  6050. // break;
  6051. // case 'm':
  6052. // printf("%f\n", mrp);
  6053. // break;
  6054. // case NUMBER:
  6055. // push(atof(op));
  6056. // break;
  6057. // case '+':
  6058. // push(pop() + pop());
  6059. // break;
  6060. // case '*':
  6061. // push(pop() * pop());
  6062. // break;
  6063. // case '-':
  6064. // operator2 = pop();
  6065. // push(pop() - operator2);
  6066. // break;
  6067. // case '/':
  6068. // operator2 = pop();
  6069. // if (operator2 != 0.0)
  6070. // push(pop() / operator2);
  6071. // else
  6072. // printf("Error: Operator 2 is 0. Cannot divide by 0.\n");
  6073. // break;
  6074. // case '%':
  6075. // operator2 = pop();
  6076. // if (operator2 != 0)
  6077. // push((int)pop() % (int)operator2);
  6078. // else
  6079. // printf("Error: Operator 2 is 0. Cannot divide by 0.\n");
  6080. // break;
  6081. // case 'p':
  6082. // temp = pop();
  6083. // push(temp);
  6084. // printf("%f", temp);
  6085. // break;
  6086. // case 'd':
  6087. // temp = pop();
  6088. // push(temp);
  6089. // push(temp);
  6090. // break;
  6091. // case 's':
  6092. // temp = pop();
  6093. // temp2 = pop();
  6094. // push(temp);
  6095. // push(temp2);
  6096. // break;
  6097. // case 'c':
  6098. // //while(isdigit(pop()));
  6099. // values[0] = '\0';
  6100. // index = 0;
  6101. // break;
  6102. // case 'q':
  6103. // push(sin(pop()));
  6104. // break;
  6105. // case 'w':
  6106. // push(cos(pop()));
  6107. // break;
  6108. // case 'e':
  6109. // operator2 = pop();
  6110. // push(pow(pop(), operator2));
  6111. // break;
  6112. // case 'u':
  6113. // printf("%s\n", ungets_string);
  6114. // while (ungets_index >= 0)
  6115. // operator_or_error_overread[index_error++] = ungets_string[ungets_index--];
  6116. // ungets_string[0] = '\0', ungets_index = 0;
  6117. // break;
  6118. // case '\n':
  6119. // printf("\t%.8f\n", mrp = pop());
  6120. // break;
  6121. // default:
  6122. // printf("Error: The program read a character using getchar() that was not a digit or a character with a switch case defined. The character is %s.\n", op);
  6123. // break;
  6124. // }
  6125. // }
  6126. // }
  6127. // terminate:
  6128. // return 0;
  6129. //}
  6130. //
  6131. //void push(double OperandValue)
  6132. //{
  6133. // if (index < MAXARRAYSIZE)
  6134. // values[index++] = OperandValue;
  6135. // else
  6136. // printf("Error: Stack full. Cannot push operand value %g.\n", OperandValue);
  6137. //}
  6138. //
  6139. //double pop(void)
  6140. //{
  6141. // if (index > 0)
  6142. // return values[--index];
  6143. // else
  6144. // {
  6145. // printf("Error: There are 0 operands stored in the stack containing numbers.\n");
  6146. // return 0.0;
  6147. // }
  6148. //}
  6149. //
  6150. //int getop(char s[])
  6151. //{
  6152. // int c;
  6153. // int d = 0;
  6154. // int i = 0;
  6155. //
  6156. // while ((s[i] = c = getchx()) == ' ' || c == '\t' || c == '\0') //skips white space by overwriting c into s[0] until an operand, operator, or error is read using getch() which reads an operand or error from getchar() overreading past a number onto an operator 123.456+. //s[i] is char op[];
  6157. // ;
  6158. // if (s[i] != '\n' && s[i] != 'u')
  6159. // ungets_string[ungets_index++] = s[i];
  6160. // else if (s[i] == '\n' || s[i] == 'u')
  6161. // ungets_string[ungets_index++] = ' ';
  6162. // i++; //'\0'
  6163. // if (!isdigit(c) && c != '.' && c != '-')
  6164. // {
  6165. // ungets_string[ungets_index++] = ' ';
  6166. // return c;
  6167. // }
  6168. // if (c == '-' && !isdigit(d = getchx()))
  6169. // {
  6170. // ungetchx(d);
  6171. // ungets_string[ungets_index++] = ' ';
  6172. // return c;
  6173. // }
  6174. // else if (c == '-' && isdigit(d))
  6175. // {
  6176. // s[i++] = c;
  6177. // ungets_string[ungets_index++] = c;
  6178. // }
  6179. // if (isdigit((c = getchx())))
  6180. // {
  6181. // ungets_string[ungets_index++] = s[i++] = c;
  6182. // while (isdigit(c = getchx()))
  6183. // ungets_string[ungets_index++] = s[i++] = c;
  6184. // }
  6185. // if (c == '.')
  6186. // {
  6187. // ungets_string[ungets_index++] = s[i++] = c;
  6188. // while (isdigit(c = getchx()))
  6189. // ungets_string[ungets_index++] = s[i++] = c;
  6190. // }
  6191. // s[i] = '\0';
  6192. // ungets_string[ungets_index++] = ' ';
  6193. // if (c != EOF)
  6194. // ungetchx(c);
  6195. //
  6196. // return NUMBER;
  6197. //}
  6198. //
  6199. //int getchx(void)
  6200. //{
  6201. // return (index_error > 0) ? operator_or_error_overread[--index_error] : getchar();
  6202. //}
  6203. //
  6204. //void ungetchx(int operator_or_error) //stores overread operators or errors in a stack operator_or_error_overread[MAXARRAYSIZE]
  6205. //{
  6206. // if (index_error >= MAXARRAYSIZE)
  6207. // printf("Error: Stack full. Cannot push character.\n");
  6208. // else
  6209. // {
  6210. // if (operator_or_error == EOF)
  6211. // operator_or_error_overread[index_error++] = '0';
  6212. // else
  6213. // operator_or_error_overread[index_error++] = operator_or_error;
  6214. // }
  6215. //}
  6216. //
  6217. //double atofx(char s[])
  6218. //{
  6219. // int i = 0;
  6220. // int sign = 1;
  6221. // int val = 0;
  6222. // int power = 1;
  6223. // int e = 0;
  6224. // double exp = 0;
  6225. // if (s[i] == '-')
  6226. // {
  6227. // sign = -1;
  6228. // i++;
  6229. // }
  6230. // else if (s[i] == '+')
  6231. // i++;
  6232. // while (isdigit(s[i]))
  6233. // val = val * 10 + (s[i++] - '0');
  6234. // if (s[i] == '.')
  6235. // {
  6236. // i++;
  6237. // while (isdigit(s[i]))
  6238. // {
  6239. // val = val * 10 + (s[i++] - '0');
  6240. // power *= 10;
  6241. // }
  6242. // }
  6243. // val = sign * val / power;
  6244. // if (s[i] == 'e' || s[i] == 'E')
  6245. // {
  6246. // i++;
  6247. // if (s[i] == '-')
  6248. // {
  6249. // i++;
  6250. // while (isdigit(s[i])) //atoi
  6251. // e = e * 10 + (s[i] - '0');
  6252. // while (e-- > 0)
  6253. // val /= 10;
  6254. // return val;
  6255. // }
  6256. // else if (s[i] == '+')
  6257. // {
  6258. // i++;
  6259. // while (isdigit(s[i])) //atoi
  6260. // e = e * 10 + (s[i] - '0');
  6261. // while (e-- > 0)
  6262. // val *= 10;
  6263. // return val;
  6264. // }
  6265. // }
  6266. // else
  6267. // return val;
  6268. //}
  6269. //
  6270. //int getline(char s[], int lim)
  6271. //{
  6272. // int c;
  6273. // int i = 0;
  6274. // while (--lim > 0 && (c = getchar()) != EOF && c != '\n')
  6275. // s[i++] = c;
  6276. // if (c == '\n')
  6277. // s[i++] = c;
  6278. // s[i] = '\0';
  6279. // return i;
  6280. //}
  6281.  
  6282. //#define NUMBER 1
  6283. //#define OFF 0
  6284. //#define ON 1
  6285. //
  6286. //int getop(char[]); //processes data into a number that is pushed onto a stack or an operand
  6287. //void push(double); //pushes a number onto a stack
  6288. //double pop(void); //pops the top number in the stack
  6289. //double atofx(char[]); //converts the string op[] into a number
  6290. //int getline(char[], int); //gets a line. characters followed by \n \0
  6291. //
  6292. //int index = 0; //index of the stack of numbers
  6293. //double values[MAXARRAYSIZE]; //stack of numbers
  6294. //
  6295. //char ungets_string[MAXARRAYSIZE]; //an array used to push back an entire line of numbers and operands onto the input
  6296. //int ungets_index = 0; //index of the ungets array
  6297. //
  6298. //char getlinearray[MAXARRAYSIZE]; //the array getline stores a line within
  6299. //int ix = 0; //the index of the array that stores the information obtained whilst getline runs
  6300. //
  6301. //main()
  6302. //{
  6303. // int operator; //variable for holding a number popped from the stack of numbers values[index]
  6304. // double operator2; //second variable for holding a number popped from the stack of numbers values[index]
  6305. // double temp; //variable for holding a value temporarily
  6306. // double temp2; //variable for holding a value temporarily
  6307. // char op[MAXARRAYSIZE]; //array used to store numbers that may be negative and floating-point. Used with atof to produce a number that is pushed onto values[index]
  6308. //
  6309. // double a = 0; /* variables for holding values and a flag to indicate if they have been defined*/
  6310. // int a_def = NO;
  6311. // double b = 0;
  6312. // int b_def = NO;
  6313. // double x = 0;
  6314. // int x_def = NO;
  6315. // double y = 0;
  6316. // int y_def = NO;
  6317. //
  6318. // char undef = 0; //variable that holds the character of the variable being undefined a, b, x, y so it can be redefined as a new value
  6319. //
  6320. // double mrp = 0.0; //most recently printed value
  6321. //
  6322. // int k = 0;
  6323. // char temparray[MAXARRAYSIZE];
  6324. // int placeholder = 0;
  6325. //
  6326. // start:
  6327. // getline(getlinearray, MAXARRAYSIZE); //gets a line and then the program goes to process the line using getop() and switch cases. all of it is commented
  6328. //
  6329. // ungets: //this label
  6330. //
  6331. // while ((operator = getop(op)) != EOF)
  6332. // {
  6333. // switch (operator) {
  6334. // case 'a':
  6335. // if (a_def == NO)
  6336. // {
  6337. // if (index > 0)
  6338. // a = pop(), a_def = YES;
  6339. // else
  6340. // a = 0;
  6341. // }
  6342. // else
  6343. // push(a);
  6344. // break;
  6345. // case 'b':
  6346. // if (b_def == NO)
  6347. // {
  6348. // if (index > 0)
  6349. // b = pop(), b_def = YES;
  6350. // else
  6351. // b = 0;
  6352. // }
  6353. // else
  6354. // push(b);
  6355. // break;
  6356. // case 'x':
  6357. // if (x_def == NO)
  6358. // {
  6359. // if (index > 0)
  6360. // x = pop(), x_def = YES;
  6361. // else
  6362. // x = 0;
  6363. // }
  6364. // else
  6365. // push(x);
  6366. // break;
  6367. // case 'y':
  6368. // if (y_def == NO)
  6369. // {
  6370. // if (index > 0)
  6371. // y = pop(), y_def = YES;
  6372. // else
  6373. // y = 0;
  6374. // }
  6375. // else
  6376. // push(y);
  6377. // break;
  6378. //
  6379. // case 'z': //undefine a variable using za zb zx zy. Then the next time the variable is used it either becomes the topmost value in the stack or 0 if the stack is empty
  6380. // undef = getchar();
  6381. // switch (undef) {
  6382. // case 'a':
  6383. // a_def = NO;
  6384. // break;
  6385. // case 'b':
  6386. // b_def = NO;
  6387. // break;
  6388. // case 'x':
  6389. // x_def = NO;
  6390. // break;
  6391. // case 'y':
  6392. // y_def = NO;
  6393. // break;
  6394. // default: printf("Error: The character after z is supposed to be a variable. The variable are a, b, x, and y. The correct syntax to undefine a variable is za, zb, zx, and zy.\n");
  6395. // break;
  6396. // }
  6397. // break;
  6398. //
  6399. // case NUMBER: //stores the number that is stored in the array op into the stack values[index] using the function push() and atof()
  6400. // push(atof(op));
  6401. // break;
  6402. //
  6403. // case '+': /* basic operations */
  6404. // push(pop() + pop());
  6405. // break;
  6406. // case '*':
  6407. // push(pop() * pop());
  6408. // break;
  6409. // case '-':
  6410. // operator2 = pop();
  6411. // push(pop() - operator2);
  6412. // break;
  6413. // case '/':
  6414. // operator2 = pop();
  6415. // if (operator2 != 0.0)
  6416. // push(pop() / operator2);
  6417. // else
  6418. // printf("Error: Operator 2 is 0. Cannot divide by 0.\n");
  6419. // break;
  6420. // case '%':
  6421. // operator2 = pop();
  6422. // if (operator2 != 0)
  6423. // push((int)pop() % (int)operator2);
  6424. // else
  6425. // printf("Error: Operator 2 is 0. Cannot divide by 0.\n");
  6426. // break;
  6427. //
  6428. // case 'm': //prints mrp
  6429. // printf("%f\n", mrp);
  6430. // break;
  6431. // case 'p': //prints topmost value of the stack values[index]. useful if you want to define a variable
  6432. // temp = pop();
  6433. // push(temp);
  6434. // printf("%f", temp);
  6435. // break;
  6436. // case 'd': //duplicated the topmost value in the stack values[index]
  6437. // temp = pop();
  6438. // push(temp);
  6439. // push(temp);
  6440. // break;
  6441. // case 's': //switches the topmost 2 values in the stack values[index]
  6442. // temp = pop();
  6443. // temp2 = pop();
  6444. // push(temp);
  6445. // push(temp2);
  6446. // break;
  6447. // case 'c': //clears the stack values[index]
  6448. // values[0] = '\0';
  6449. // index = 0;
  6450. // break;
  6451. //
  6452. // case 'q': //sin(x)
  6453. // push(sin(pop()));
  6454. // break;
  6455. // case 'w': //cos(x)
  6456. // push(cos(pop()));
  6457. // break;
  6458. // case 'e': //power(x, y)
  6459. // operator2 = pop();
  6460. // push(pow(pop(), operator2));
  6461. // break;
  6462. //
  6463. // //case 'u': //ungets: 'u': places every character that has been read before 'u' into the array getlinearray[ix] being processed in getop() and creating evaluations of the switch cases
  6464. // // //Example: 1 2 + u 1 \n should store 1 store 2 add 1 and 2 storing 3 then store 1 store 2 add 1 and 2 storing three store 1 then \n print out 1 and values 3 and 3 should be in values[index]
  6465. // // //if two 'u' are in the array getlinearray() then this is a label for the operation ungets 'u' to repeat and replace the character 'u' with every character before it. Example: 1 2 u 3 u 1 \n should store 1 store 2 store 1 store 2 store 3 store 1 store 2 store 1 store 2 store 3 store 1 \n print 1
  6466. // // //and values[index] should be 1 2 1 2 3 1 2 1 2 3
  6467. // //moreungets:
  6468. // // k = 0;
  6469. // // placeholder = ix - 1; //placeholder = ix - 1 is where 'u' is.
  6470. // // printf("%s\n", ungets_string); //prints out the ungets_string so I see what string is placed onto getlinearray[] processed by getop()
  6471. // //
  6472. // // while (getlinearray[placeholder] != '\0') //stores everything after 'u' into temp
  6473. // // {
  6474. // // temparray[k] = getlinearray[placeholder];
  6475. // // k++, placeholder++;
  6476. // // }
  6477. // // temparray[k] = '\0';
  6478. //
  6479. // // while (ungets_index >= 0) //inserts ungets_string[] into getlinearray[] beginning where 'u' was stored
  6480. // // {
  6481. // // getlinearray[placeholder] = ungets_string[ungets_index];
  6482. // // placeholder++, ungets_index--;
  6483. // // }
  6484. // // ungets_string[0] = '\0', ungets_index = 0; //resets ungets_string[] for next use 'u'
  6485. //
  6486. // // k = 0;
  6487. // // while (temparray[k] != '\0') //restores the rest of the array getlinearray[] before the insertion of ungets_string[]
  6488. // // {
  6489. // // getlinearray[placeholder] = temparray[k];
  6490. // // k++, placeholder++;
  6491. // // }
  6492. // // getlinearray[placeholder++] = '\0';
  6493. //
  6494. // // ix = 0;
  6495. // // while (getlinearray[ix] != '\0') //checks getlinerarray[] for any more 'u'
  6496. // // {
  6497. // // if (getlinearray[ix] == 'u') //IF 'u' is found repeat
  6498. // // {
  6499. // // ix++;
  6500. // // goto moreungets;
  6501. // // }
  6502. // // else //else store everything into ungets_string for the next time 'u' may be read. //ungets_string[] can be cleared with 'r'.
  6503. // // {
  6504. // // ungets_string[ungets_index] = getlinearray[ix];
  6505. // // ix++, ungets_index++;
  6506. // // }
  6507. // // }
  6508. // // goto ungets;
  6509. // // break;
  6510. // //case 'r': //clears ungets
  6511. // // ungets_string[0] = '\0', ungets_index = 0;
  6512. // // break;
  6513. //
  6514. // case '\n': //prints the topmost value of the stack values[index], clears getlinearray[] so a new line can be read and processed and saves mrp.
  6515. // mrp = pop();
  6516. // printf("\t%.8f\n", mrp);
  6517. // getlinearray[0] = '\0', ix = 0;
  6518. // goto start;
  6519. // break;
  6520. // case '!': //terminates
  6521. // goto terminate;
  6522. // default: //default: error
  6523. // printf("Error: The program read a character using getchar() that was not a digit or a character with a switch case defined. The character is %s.\n", op);
  6524. // break;
  6525. // }
  6526. // }
  6527. // terminate:
  6528. // return 0;
  6529. //}
  6530. //void push(double OperandValue)
  6531. //{
  6532. // if (index < MAXARRAYSIZE) //IF THERE IS SPACE IN THE STACK values[index] STORE THE VALUE SENT TO THE FUNCTION else error
  6533. // values[index++] = OperandValue;
  6534. // else
  6535. // printf("Error: Stack full. Cannot push operand value %g.\n", OperandValue);
  6536. //}
  6537. //
  6538. //double pop(void)
  6539. //{
  6540. // if (index > 0) //IF THERE IS A VALUE IN values[index] POP/RETURN THE VALUE TO THE FUNCTION CALL pop() else error
  6541. // return values[--index];
  6542. // else
  6543. // {
  6544. // printf("Error: There are 0 operands stored in the stack containing numbers.\n");
  6545. // return 0.0;
  6546. // }
  6547. //}
  6548. //
  6549. //int getop(char s[]) //processes getline(getlinearray[], MAXARRAYSIZE) and ungets
  6550. //{
  6551. // int j = 0;
  6552. //
  6553. // while (getlinearray[ix] == ' ' || getlinearray[ix] == '\t' || getlinearray[ix] == '\0') //skips white space
  6554. // ix++;
  6555. //
  6556. // if (getlinearray[ix] != '\n' && getlinearray[ix] != 'u') //save character or number into op "s[]" and ungets_string for ungets
  6557. // s[j++] = ungets_string[ungets_index++] = getlinearray[ix];
  6558. //
  6559. // else if (getlinearray[ix] == '\n' || getlinearray[ix] == 'u') //don't save 'u' and '\n' into ungets
  6560. // ungets_string[ungets_index++] = ' ';
  6561. //
  6562. // if (!isdigit(getlinearray[ix]) && getlinearray[ix] != '.' && getlinearray[ix] != '-') //return character
  6563. // {
  6564. // ungets_string[ungets_index++] = ' ';
  6565. // return getlinearray[ix++];
  6566. // }
  6567. // if (getlinearray[ix] == '-' && !isdigit(getlinearray[ix + 1])) //return '-'
  6568. // {
  6569. // ungets_string[ungets_index++] = ' ';
  6570. // return getlinearray[ix++];
  6571. // }
  6572. // else if (getlinearray[ix] == '-' && isdigit(getlinearray[ix+1])) //negative number
  6573. // {
  6574. // ix++;
  6575. // s[j] = getlinearray[ix]; //save digit
  6576. // ungets_string[ungets_index] = getlinearray[ix];
  6577. // j++, ungets_index++;
  6578. // }
  6579. //
  6580. // if (isdigit(getlinearray[ix + 1])) //save number
  6581. // {
  6582. // ix++;
  6583. // ungets_string[ungets_index] = s[j] = getlinearray[ix];
  6584. // ix++, j++, ungets_index++;
  6585. // while (isdigit(getlinearray[ix]))
  6586. // {
  6587. // ungets_string[ungets_index] = s[j] = getlinearray[ix];
  6588. // ix++, j++, ungets_index++;
  6589. // }
  6590. // }
  6591. // if (getlinearray[ix] == '.') //save fractional part of number
  6592. // {
  6593. // ix++;
  6594. // ungets_string[ungets_index++] = s[j++] = getlinearray[ix];
  6595. // ix++;
  6596. // while (isdigit(getlinearray[ix]))
  6597. // {
  6598. // ungets_string[ungets_index] = s[j] = getlinearray[ix];
  6599. // ix++, j++, ungets_index++;
  6600. // }
  6601. // }
  6602. // ix++;
  6603. // s[j] = '\0';
  6604. // ungets_string[ungets_index++] = ' ';
  6605. //
  6606. // return NUMBER; //return to getop() and store op[] into values[index] using atof()
  6607. //}
  6608. //
  6609. //double atofx(char s[]) //converts a string to a floating point number
  6610. //{
  6611. // int i = 0;
  6612. // int sign = 1;
  6613. // int val = 0;
  6614. // int power = 1;
  6615. // int e = 0;
  6616. // double exp = 0;
  6617. // if (s[i] == '-')
  6618. // {
  6619. // sign = -1;
  6620. // i++;
  6621. // }
  6622. // else if (s[i] == '+')
  6623. // i++;
  6624. // while (isdigit(s[i]))
  6625. // val = val * 10 + (s[i++] - '0');
  6626. // if (s[i] == '.')
  6627. // {
  6628. // i++;
  6629. // while (isdigit(s[i]))
  6630. // {
  6631. // val = val * 10 + (s[i++] - '0');
  6632. // power *= 10;
  6633. // }
  6634. // }
  6635. // val = sign * val / power;
  6636. // if (s[i] == 'e' || s[i] == 'E')
  6637. // {
  6638. // i++;
  6639. // if (s[i] == '-')
  6640. // {
  6641. // i++;
  6642. // while (isdigit(s[i]))
  6643. // e = e * 10 + (s[i] - '0');
  6644. // while (e-- > 0)
  6645. // val /= 10;
  6646. // return val;
  6647. // }
  6648. // else if (s[i] == '+')
  6649. // {
  6650. // i++;
  6651. // while (isdigit(s[i]))
  6652. // e = e * 10 + (s[i] - '0');
  6653. // while (e-- > 0)
  6654. // val *= 10;
  6655. // return val;
  6656. // }
  6657. // }
  6658. // else
  6659. // return val;
  6660. //}
  6661. //
  6662. //int getline(char s[], int lim) //stores characters into an array, ends with '\n' '\0'
  6663. //{
  6664. // int c;
  6665. // int i = 0;
  6666. // while (--lim > 0 && (c = getchar()) != EOF && c != '\n')
  6667. // s[i++] = c;
  6668. // if (c == '\n')
  6669. // s[i++] = c;
  6670. // s[i] = '\0';
  6671. // return i;
  6672. //}
  6673.  
  6674. //#define NUMBER 1
  6675. //
  6676. //int getop(char[]); //processes data into a number that is pushed onto a stack or an operand
  6677. //void push(double); //stores argument into values[]
  6678. //double pop(void); //returns the top value in stack values[]
  6679. //int getchx(void); //reads from operator_or_error_overread[] if it has anything, else uses getchar()
  6680. //void ungetchx(int); //stores argument in operator_or_error_overread[]
  6681. //double atofx(char[]); //converts the string op[] into a number
  6682. //void cleararray(char[], int);
  6683. //
  6684. //int index = 0; //index of the stack of numbers
  6685. //double values[MAXARRAYSIZE]; //stack of numbers
  6686. //
  6687. //char ungets_string[MAXARRAYSIZE]; //an array used to push back an entire line of numbers and operands onto the input
  6688. //int ungets_index = 0; //index of the ungets array
  6689. //
  6690. //char operator_or_error_overread[MAXARRAYSIZE]; //stored overread characters: 1.2+ saves +, here. Then getc() reads from here first, instead of using getchar(). Also stores everything from ungets[], ungets 'u' pushes a string onto the input using this array that getc() reads from, instead of reading with getchar()
  6691. //int index_error = 0; //index of operator_or_error_overread[]
  6692. //
  6693. //
  6694. //main()
  6695. //{
  6696. // int operator; //variable for holding a number popped from the stack of numbers values[index]
  6697. // double operator2; //second variable for holding a number popped from the stack of numbers values[index]
  6698. // double temp; //variable for holding a value temporarily
  6699. // double temp2; //variable for holding a value temporarily
  6700. // char op[MAXARRAYSIZE]; //array used to store numbers that may be negative and floating-point. Used with atof to produce a number that is pushed onto values[index]
  6701. //
  6702. // double a = 0; /* variables for holding values and a flag to indicate if they have been defined*/
  6703. // int a_def = NO;
  6704. // double b = 0;
  6705. // int b_def = NO;
  6706. // double x = 0;
  6707. // int x_def = NO;
  6708. // double y = 0;
  6709. // int y_def = NO;
  6710. // int undef = 0; /* variables for holding values and a flag to indicate if they have been defined*/
  6711. //
  6712. // double mrp = 0.0; //most recently printed value
  6713. //
  6714. // int placeholder = 0; //used for multiple ungets 'u' in one line of input
  6715. //
  6716. // while ((operator = getop(op)) != EOF)
  6717. // {
  6718. // switch (operator) {
  6719. //
  6720. //
  6721. //
  6722. // case 'a': /*define and undefine variables*/
  6723. // if (a_def == NO)
  6724. // {
  6725. // if (index > 0)
  6726. // a = pop(), a_def = YES;
  6727. // else
  6728. // a = 0;
  6729. // }
  6730. // else
  6731. // push(a);
  6732. // break;
  6733. // case 'b':
  6734. // if (b_def == NO)
  6735. // b = pop(), b_def = YES;
  6736. // else
  6737. // push(b);
  6738. // break;
  6739. // case 'x':
  6740. // if (x_def == NO)
  6741. // x = pop(), x_def = YES;
  6742. // else
  6743. // push(a);
  6744. // break;
  6745. // case 'y':
  6746. // if (y_def == NO)
  6747. // y = pop(), y_def = YES;
  6748. // else
  6749. // push(a);
  6750. // break;
  6751. // case 'z': //assuming appropriate usage //undefine variable
  6752. // undef = getchar();
  6753. // switch (undef) {
  6754. // case 'a':
  6755. // a_def = NO;
  6756. // break;
  6757. // case 'b':
  6758. // b_def = NO;
  6759. // break;
  6760. // case 'x':
  6761. // x_def = NO;
  6762. // break;
  6763. // case 'y':
  6764. // y_def = NO;
  6765. // break;
  6766. // default: printf("Error: The character after z is supposed to be a variable. The variable are a, b, x, and y. The correct syntax to undefine a variable is za, zb, zx, and zy.\n");
  6767. // break;
  6768. // }
  6769. // break; /*define and undefine variables*/
  6770. //
  6771. //
  6772. //
  6773. // case NUMBER:
  6774. // push(atof(op));
  6775. // break;
  6776. // case '+':
  6777. // push(pop() + pop());
  6778. // break;
  6779. // case '*':
  6780. // push(pop() * pop());
  6781. // break;
  6782. // case '-':
  6783. // operator2 = pop();
  6784. // push(pop() - operator2);
  6785. // break;
  6786. // case '/':
  6787. // operator2 = pop();
  6788. // if (operator2 != 0.0)
  6789. // push(pop() / operator2);
  6790. // else
  6791. // printf("Error: Operator 2 is 0. Cannot divide by 0.\n");
  6792. // break;
  6793. // case '%':
  6794. // operator2 = pop();
  6795. // if (operator2 != 0)
  6796. // push((int)pop() % (int)operator2);
  6797. // else
  6798. // printf("Error: Operator 2 is 0. Cannot divide by 0.\n");
  6799. // break;
  6800. // case 'q':
  6801. // push(sin(pop()));
  6802. // break;
  6803. // case 'w':
  6804. // push(cos(pop()));
  6805. // break;
  6806. // case 'e':
  6807. // operator2 = pop();
  6808. // push(pow(pop(), operator2));
  6809. // break;
  6810. //
  6811. //
  6812. //
  6813. // case 'm': //print mrp
  6814. // printf("%f\n", mrp);
  6815. // break;
  6816. // case 'p': //print topmost value in stack values[]
  6817. // temp = pop();
  6818. // push(temp);
  6819. // printf("%f", temp);
  6820. // break;
  6821. // case 'd': //duplicate topmost value in stack values[]
  6822. // temp = pop();
  6823. // push(temp);
  6824. // push(temp);
  6825. // break;
  6826. // case 's': //swap topmost two values in stack values[]
  6827. // temp = pop();
  6828. // temp2 = pop();
  6829. // push(temp);
  6830. // push(temp2);
  6831. // break;
  6832. // case 'c': //clear values[]
  6833. // cleararray(values, index);
  6834. // index = 0;
  6835. // break;
  6836. //
  6837. //
  6838. //
  6839. // case 'u': //places everything before 'u' in the line of input where 'u' was
  6840. // printf("%s\n", ungets_string);
  6841. // placeholder = ungets_index;
  6842. // while (ungets_index >= 0)
  6843. // operator_or_error_overread[index_error++] = ungets_string[ungets_index--];
  6844. // ungets_index = placeholder;
  6845. // break;
  6846. // case 'r': //clears ungets_string[]
  6847. // printf("Cleared ungets_string[]: %s\n", ungets_string);
  6848. // cleararray(ungets_string, ungets_index);
  6849. // printf("Current ungets_string: %s\n", ungets_string);
  6850. // ungets_index = 0;
  6851. // break;
  6852. // case 'v':
  6853. // printf("%s\n", ungets_string);
  6854. // break;
  6855. //
  6856. // case '\n': //prints the topmost value of values[], saves mrp
  6857. // mrp = pop();
  6858. // printf("\t%.8f\n", mrp);
  6859. // break;
  6860. // case '!': //end program
  6861. // goto terminate;
  6862. // break;
  6863. // default: //error
  6864. // printf("Error: The program read a character using getchar() that was not a digit or a character with a switch case defined. The character is %s.\n", op);
  6865. // break;
  6866. // }
  6867. // }
  6868. // terminate:
  6869. // return 0;
  6870. //}
  6871. //
  6872. //void push(double OperandValue) //stores argument into stack values[], else full
  6873. //{
  6874. // if (index < MAXARRAYSIZE)
  6875. // values[index++] = OperandValue;
  6876. // else
  6877. // printf("Error: Stack full. Cannot push operand value %g.\n", OperandValue);
  6878. //}
  6879. //double pop(void) //returns topmost value of values[], else error
  6880. //{
  6881. // if (index > 0)
  6882. // return values[--index];
  6883. // else
  6884. // {
  6885. // printf("Error: There are 0 operands stored in the stack containing numbers.\n");
  6886. // return 0.0;
  6887. // }
  6888. //}
  6889. //
  6890. //int getop(char s[]) //process characters and return to the switch with a number or a character
  6891. //{
  6892. // int c;
  6893. // int d = 0;
  6894. // int i = 0;
  6895. //
  6896. // while ((s[i] = c = getchx()) == ' ' || c == '\t' || c == '\0') //skips white space by overwriting c into s[0] until an operand, operator, or error is read using getch() which reads an operand, operator, or error from getchar() overreading past any number onto a space or an operator 1.2+ or 1.2 .
  6897. // ;
  6898. //
  6899. // if (s[i] != '\n' && s[i] != 'u')
  6900. // ungets_string[ungets_index++] = s[i]; //saves all characters into ungets_string[] that are not '\n' and 'u'. '\n' would create printing errors and 'u' would create infinite ungets operations
  6901. //
  6902. // else if (s[i] == '\n' || s[i] == 'u')
  6903. // ungets_string[ungets_index++] = ' '; //spaces are used to avoid 'u' '\n' and '\0' repeating in ungets_string[].
  6904. //
  6905. // i++; //increment op = s[i] to the next free space to save numbers and decimals
  6906. //
  6907. // if (!isdigit(c) && c != '.' && c != '-') //saves character operand and returns character operand
  6908. // {
  6909. // return c;
  6910. // ungets_string[ungets_index++] = ' ';
  6911. // }
  6912. //
  6913. // if (c == '-')
  6914. // d = getchx();
  6915. //
  6916. // if (c == '-' && !isdigit(d)) //saves negative '-' character and return character '-'
  6917. // {
  6918. // ungetchx(d);
  6919. // ungets_string[ungets_index++] = ' ';
  6920. // return c;
  6921. // }
  6922. // else if (c == '-' && isdigit(d)) //saves first digit after '-'
  6923. // {
  6924. // s[i++] = d;
  6925. // ungets_string[ungets_index++] = d;
  6926. // }
  6927. //
  6928. // if (isdigit((c = getchx()))) //saves number
  6929. // {
  6930. // ungets_string[ungets_index++] = s[i++] = c;
  6931. // while (isdigit(c = getchx()))
  6932. // ungets_string[ungets_index++] = s[i++] = c;
  6933. // }
  6934. //
  6935. // if (c == '.') //saves decimals
  6936. // {
  6937. // ungets_string[ungets_index++] = s[i++] = c;
  6938. // while (isdigit(c = getchx()))
  6939. // ungets_string[ungets_index++] = s[i++] = c;
  6940. // }
  6941. //
  6942. // if (c != EOF) //ungets the overread character: 1.2+, ungets +, saves 1.2 in op[].
  6943. // ungetchx(c);
  6944. //
  6945. // s[i] = '\0';
  6946. // ungets_string[ungets_index++] = ' '; //spaces are used to avoid 'u' '\n' and '\0' repeating in ungets_string[].
  6947. //
  6948. // return NUMBER;
  6949. //}
  6950. //
  6951. //int getchx(void) //if there is a value in operator_or_error_overread[] read from it, else use getchar()
  6952. //{
  6953. // return (index_error > 0) ? operator_or_error_overread[--index_error] : getchar();
  6954. //}
  6955. //void ungetchx(int operator_or_error) //if there is space in operator_or_error_overread[] store operator_or_error, else error
  6956. //{
  6957. // if (index_error >= MAXARRAYSIZE)
  6958. // printf("Error: Stack full. Cannot push character.\n");
  6959. // else
  6960. // {
  6961. // if (operator_or_error == EOF)
  6962. // operator_or_error_overread[index_error++] = '0';
  6963. // else
  6964. // operator_or_error_overread[index_error++] = operator_or_error;
  6965. // }
  6966. //}
  6967. //
  6968. //double atofx(char s[]) //convert string to floating-point number
  6969. //{
  6970. // int i = 0;
  6971. // int sign = 1;
  6972. // int val = 0;
  6973. // int power = 1;
  6974. // int e = 0;
  6975. // double exp = 0;
  6976. // if (s[i] == '-')
  6977. // {
  6978. // sign = -1;
  6979. // i++;
  6980. // }
  6981. // else if (s[i] == '+')
  6982. // i++;
  6983. // while (isdigit(s[i]))
  6984. // val = val * 10 + (s[i++] - '0');
  6985. // if (s[i] == '.')
  6986. // {
  6987. // i++;
  6988. // while (isdigit(s[i]))
  6989. // {
  6990. // val = val * 10 + (s[i++] - '0');
  6991. // power *= 10;
  6992. // }
  6993. // }
  6994. // val = sign * val / power;
  6995. // if (s[i] == 'e' || s[i] == 'E')
  6996. // {
  6997. // i++;
  6998. // if (s[i] == '-')
  6999. // {
  7000. // i++;
  7001. // while (isdigit(s[i])) //atoi
  7002. // e = e * 10 + (s[i] - '0');
  7003. // while (e-- > 0)
  7004. // val /= 10;
  7005. // return val;
  7006. // }
  7007. // else if (s[i] == '+')
  7008. // {
  7009. // i++;
  7010. // while (isdigit(s[i])) //atoi
  7011. // e = e * 10 + (s[i] - '0');
  7012. // while (e-- > 0)
  7013. // val *= 10;
  7014. // return val;
  7015. // }
  7016. // }
  7017. // else
  7018. // return val;
  7019. //}
  7020. //
  7021. //void cleararray(char array[], int endofdata) //clear array
  7022. //{
  7023. // int i = 0;
  7024. // while (i <= endofdata)
  7025. // {
  7026. // array[i] = '\0';
  7027. // i++;
  7028. // }
  7029. //}
  7030.  
  7031. //#define NUMBER 1
  7032. //
  7033. //int getop(char[]); //processes data into a number that is pushed onto a stack or an operand
  7034. //void push(double); //stores argument into values[]
  7035. //double pop(void); //returns the top value in stack values[]
  7036. //int getchx(void); //reads from operator_or_error_overread[] if it has anything, else uses getchar()
  7037. //void ungetchx(int); //stores argument in operator_or_error_overread[]
  7038. //double atofx(char[]); //converts the string op[] into a number
  7039. //void cleararray(char[], int);
  7040. //void cleararrayfrom_to(char[], int, int);
  7041. //int getline(char[], int);
  7042. //
  7043. //char getchxungetchx[MAXARRAYSIZE];
  7044. //int gi = 0;
  7045. //
  7046. //char op[MAXARRAYSIZE]; //array used to store numbers that may be negative and floating-point. Used with atof to produce a number that is pushed onto values[index]
  7047. //
  7048. //int index = 0; //index of the stack of numbers
  7049. //double values[MAXARRAYSIZE]; //stack of numbers
  7050. //
  7051. //char ungets_string[MAXARRAYSIZE]; //an array used to push back an entire line of numbers and operands onto the input
  7052. //int ungets_index = 0; //index of the ungets array
  7053. //char temparray[MAXARRAYSIZE];
  7054. //int ti = 0;
  7055. //
  7056. //char operator_or_error_overread[MAXARRAYSIZE]; //stored overread characters: 1.2+ saves +, here. Then getc() reads from here first, instead of using getchar(). Also stores everything from ungets[], ungets 'u' pushes a string onto the input using this array that getc() reads from, instead of reading with getchar()
  7057. //int index_error = 0; //index of operator_or_error_overread[]
  7058. //
  7059. //
  7060. //main()
  7061. //{
  7062. // int operator; //variable for holding a number popped from the stack of numbers values[index]
  7063. // double operator2; //second variable for holding a number popped from the stack of numbers values[index]
  7064. // double temp; //variable for holding a value temporarily
  7065. // double temp2; //variable for holding a value temporarily
  7066. //
  7067. // double a = 0; /* variables for holding values and a flag to indicate if they have been defined*/
  7068. // int a_def = NO;
  7069. // double b = 0;
  7070. // int b_def = NO;
  7071. // double x = 0;
  7072. // int x_def = NO;
  7073. // double y = 0;
  7074. // int y_def = NO;
  7075. // int undef = 0; /* variables for holding values and a flag to indicate if they have been defined*/
  7076. //
  7077. // double mrp = 0.0; //most recently printed value
  7078. //
  7079. // int placeholder = 0; //used for multiple ungets 'u' in one line of input
  7080. // int placeholder_gi = 0;
  7081. // int u = 0;
  7082. //
  7083. // Start:
  7084. // while (getline(getchxungetchx, MAXARRAYSIZE) > 0)
  7085. // {
  7086. // while ((operator = getop(op)) != '\0')
  7087. // {
  7088. // switch (operator) {
  7089. //
  7090. // case 'a': /*define and undefine variables*/
  7091. // if (a_def == NO)
  7092. // {
  7093. // if (index > 0)
  7094. // a = pop(), a_def = YES;
  7095. // else
  7096. // a = 0;
  7097. // }
  7098. // else
  7099. // push(a);
  7100. // break;
  7101. // case 'b':
  7102. // if (b_def == NO)
  7103. // b = pop(), b_def = YES;
  7104. // else
  7105. // push(b);
  7106. // break;
  7107. // case 'x':
  7108. // if (x_def == NO)
  7109. // x = pop(), x_def = YES;
  7110. // else
  7111. // push(a);
  7112. // break;
  7113. // case 'y':
  7114. // if (y_def == NO)
  7115. // y = pop(), y_def = YES;
  7116. // else
  7117. // push(a);
  7118. // break;
  7119. // case 'z': //assuming appropriate usage //undefine variable
  7120. // undef = getchar();
  7121. // switch (undef) {
  7122. // case 'a':
  7123. // a_def = NO;
  7124. // break;
  7125. // case 'b':
  7126. // b_def = NO;
  7127. // break;
  7128. // case 'x':
  7129. // x_def = NO;
  7130. // break;
  7131. // case 'y':
  7132. // y_def = NO;
  7133. // break;
  7134. // default: printf("Error: The character after z is supposed to be a variable. The variable are a, b, x, and y. The correct syntax to undefine a variable is za, zb, zx, and zy.\n");
  7135. // break;
  7136. // }
  7137. // break; /*define and undefine variables*/
  7138. //
  7139. //
  7140. //
  7141. // case NUMBER:
  7142. // push(atof(op));
  7143. // break;
  7144. // case '+':
  7145. // push(pop() + pop());
  7146. // break;
  7147. // case '*':
  7148. // push(pop() * pop());
  7149. // break;
  7150. // case '-':
  7151. // operator2 = pop();
  7152. // push(pop() - operator2);
  7153. // break;
  7154. // case '/':
  7155. // operator2 = pop();
  7156. // if (operator2 != 0.0)
  7157. // push(pop() / operator2);
  7158. // else
  7159. // printf("Error: Operator 2 is 0. Cannot divide by 0.\n");
  7160. // break;
  7161. // case '%':
  7162. // operator2 = pop();
  7163. // if (operator2 != 0)
  7164. // push((int)pop() % (int)operator2);
  7165. // else
  7166. // printf("Error: Operator 2 is 0. Cannot divide by 0.\n");
  7167. // break;
  7168. // case 'q':
  7169. // push(sin(pop()));
  7170. // break;
  7171. // case 'w':
  7172. // push(cos(pop()));
  7173. // break;
  7174. // case 'e':
  7175. // operator2 = pop();
  7176. // push(pow(pop(), operator2));
  7177. // break;
  7178. //
  7179. //
  7180. //
  7181. // case 'm': //print mrp
  7182. // printf("%f\n", mrp);
  7183. // break;
  7184. // case 'p': //print topmost value in stack values[]
  7185. // temp = pop();
  7186. // push(temp);
  7187. // printf("%f", temp);
  7188. // break;
  7189. // case 'd': //duplicate topmost value in stack values[]
  7190. // temp = pop();
  7191. // push(temp);
  7192. // push(temp);
  7193. // break;
  7194. // case 's': //swap topmost two values in stack values[]
  7195. // temp = pop();
  7196. // temp2 = pop();
  7197. // push(temp);
  7198. // push(temp2);
  7199. // break;
  7200. // case 'c': //clear values[]
  7201. // cleararray(values, index);
  7202. // index = 0;
  7203. // break;
  7204. //
  7205. //
  7206. //
  7207. // case 'u': //places everything before 'u' in the line of input where 'u' was
  7208. // printf("%s\n", ungets_string);
  7209. //
  7210. // placeholder_gi = gi;
  7211. //
  7212. // while (getchxungetchx[placeholder_gi] != '\n')
  7213. // {
  7214. // temparray[ti] = getchxungetchx[placeholder_gi];
  7215. // ti++, placeholder_gi++;
  7216. // }
  7217. //
  7218. // cleararrayfrom_to(getchxungetchx, gi - 1, MAXARRAYSIZE - 1);
  7219. //
  7220. // temparray[ti] = '\n';
  7221. //
  7222. // placeholder = ungets_index;
  7223. // placeholder_gi = gi - 1;
  7224. //
  7225. // u = 0;
  7226. // while (u < placeholder)
  7227. // {
  7228. // getchxungetchx[placeholder_gi] = ungets_string[u];
  7229. // placeholder_gi++;
  7230. // u++;
  7231. // }
  7232. //
  7233. // ti = 0;
  7234. //
  7235. // while (temparray[ti] != '\n')
  7236. // {
  7237. // getchxungetchx[placeholder_gi] = temparray[ti];
  7238. // ti++, placeholder_gi++;
  7239. // }
  7240. //
  7241. // getchxungetchx[placeholder_gi] = '\n';
  7242. //
  7243. // gi = gi - 1;
  7244. // cleararray(temparray, ti);
  7245. //
  7246. // printf("%sX\n", getchxungetchx);
  7247. // break;
  7248. // case 'r': //clears ungets_string[]
  7249. // printf("Cleared ungets_string[]: %s\n", ungets_string);
  7250. // cleararray(ungets_string, ungets_index);
  7251. // printf("Current ungets_string: %s\n", ungets_string);
  7252. // ungets_index = 0;
  7253. // break;
  7254. // case 'v':
  7255. // printf("%s\n", ungets_string);
  7256. // break;
  7257. //
  7258. // case '\n': //prints the topmost value of values[], saves mrp
  7259. // mrp = pop();
  7260. // printf("\t%.8f\n", mrp);
  7261. // cleararray(getchxungetchx, gi);
  7262. // gi = 0;
  7263. // goto Start;
  7264. // break;
  7265. // case '!': //end program
  7266. // goto terminate;
  7267. // break;
  7268. // default: //error
  7269. // printf("Error: The program read a character using getchar() that was not a digit or a character with a switch case defined. The character is %s.\n", op);
  7270. // break;
  7271. // }
  7272. // }
  7273. // }
  7274. // terminate:
  7275. // return 0;
  7276. //}
  7277. //
  7278. //void push(double OperandValue) //stores argument into stack values[], else full
  7279. //{
  7280. // if (index < MAXARRAYSIZE)
  7281. // values[index++] = OperandValue;
  7282. // else
  7283. // printf("Error: Stack full. Cannot push operand value %g.\n", OperandValue);
  7284. //}
  7285. //double pop(void) //returns topmost value of values[], else error
  7286. //{
  7287. // if (index > 0)
  7288. // return values[--index];
  7289. // else
  7290. // {
  7291. // printf("Error: There are 0 operands stored in the stack containing numbers.\n");
  7292. // return 0.0;
  7293. // }
  7294. //}
  7295. //
  7296. ////getchx with I, ungetchx with D
  7297. ////array for op
  7298. //int getop(char s[]) //process characters and return to the switch with a number or a character
  7299. //{
  7300. // int i = 0;
  7301. //
  7302. // while ((s[i] = getchxungetchx[gi]) == ' ' || getchxungetchx[gi] == '\t') //skips white space by overwriting c into s[0] until an operand, operator, or error is read using getch() which reads an operand, operator, or error from getchar() overreading past any number onto a space or an operator 1.2+ or 1.2 .
  7303. // gi++;
  7304. //
  7305. // if (s[i] != '\n' && s[i] != 'u')
  7306. // ungets_string[ungets_index++] = s[i]; //saves all characters into ungets_string[] that are not '\n' and 'u'. '\n' would create printing errors and 'u' would create infinite ungets operations
  7307. //
  7308. // else if (s[i] == 'u')
  7309. // ungets_string[ungets_index++] = ' '; //spaces are used to avoid 'u' '\n' and '\0' repeating in ungets_string[].
  7310. //
  7311. // else if (s[i] == '\n')
  7312. // {
  7313. // gi++;
  7314. // ungets_string[ungets_index++] = ' ';
  7315. // return s[i];
  7316. // }
  7317. //
  7318. // if (!isdigit(s[i]) && s[i] != '.' && s[i] != '-') //saves character operand and returns character operand
  7319. // {
  7320. // gi++;
  7321. // ungets_string[ungets_index++] = ' ';
  7322. // return s[i];
  7323. // }
  7324. //
  7325. // if (s[i] == '-' && !isdigit(getchxungetchx[gi+1])) //saves negative '-' character and return character '-'
  7326. // {
  7327. // gi++;
  7328. // ungets_string[ungets_index++] = ' ';
  7329. // return s[i];
  7330. // }
  7331. // else if (s[i] == '-' && isdigit(getchxungetchx[gi+1])) //saves first digit after '-'
  7332. // {
  7333. // i++, gi++;
  7334. // s[i] = getchxungetchx[gi];
  7335. // ungets_string[ungets_index++] = s[i];
  7336. // }
  7337. //
  7338. // if (isdigit(getchxungetchx[gi])) //saves number
  7339. // {
  7340. // i++;
  7341. // while (isdigit(getchxungetchx[++gi]))
  7342. // ungets_string[ungets_index++] = s[i++] = getchxungetchx[gi];
  7343. // }
  7344. //
  7345. // if (getchxungetchx[gi] == '.') //saves decimals
  7346. // {
  7347. // i++, gi++;
  7348. // ungets_string[ungets_index++] = s[i++] = getchxungetchx[gi];
  7349. // while (isdigit(getchxungetchx[++gi]))
  7350. // ungets_string[ungets_index++] = s[i++] = getchxungetchx[gi];
  7351. // }
  7352. //
  7353. // s[i] = '\0';
  7354. //
  7355. // ungets_string[ungets_index++] = ' '; //spaces are used to avoid 'u' '\n' and '\0' repeating in ungets_string[].
  7356. //
  7357. // return NUMBER;
  7358. //}
  7359. //
  7360. //int getchx(void) //if there is a value in operator_or_error_overread[] read from it, else use getchar()
  7361. //{
  7362. // return (index_error > 0) ? operator_or_error_overread[--index_error] : getchar();
  7363. //}
  7364. //void ungetchx(int operator_or_error) //if there is space in operator_or_error_overread[] store operator_or_error, else error
  7365. //{
  7366. // if (index_error >= MAXARRAYSIZE)
  7367. // printf("Error: Stack full. Cannot push character.\n");
  7368. // else
  7369. // {
  7370. // if (operator_or_error == EOF)
  7371. // operator_or_error_overread[index_error++] = '0';
  7372. // else
  7373. // operator_or_error_overread[index_error++] = operator_or_error;
  7374. // }
  7375. //}
  7376. //
  7377. //double atofx(char s[]) //convert string to floating-point number
  7378. //{
  7379. // int i = 0;
  7380. // int sign = 1;
  7381. // int val = 0;
  7382. // int power = 1;
  7383. // int e = 0;
  7384. // double exp = 0;
  7385. // if (s[i] == '-')
  7386. // {
  7387. // sign = -1;
  7388. // i++;
  7389. // }
  7390. // else if (s[i] == '+')
  7391. // i++;
  7392. // while (isdigit(s[i]))
  7393. // val = val * 10 + (s[i++] - '0');
  7394. // if (s[i] == '.')
  7395. // {
  7396. // i++;
  7397. // while (isdigit(s[i]))
  7398. // {
  7399. // val = val * 10 + (s[i++] - '0');
  7400. // power *= 10;
  7401. // }
  7402. // }
  7403. // val = sign * val / power;
  7404. // if (s[i] == 'e' || s[i] == 'E')
  7405. // {
  7406. // i++;
  7407. // if (s[i] == '-')
  7408. // {
  7409. // i++;
  7410. // while (isdigit(s[i])) //atoi
  7411. // e = e * 10 + (s[i] - '0');
  7412. // while (e-- > 0)
  7413. // val /= 10;
  7414. // return val;
  7415. // }
  7416. // else if (s[i] == '+')
  7417. // {
  7418. // i++;
  7419. // while (isdigit(s[i])) //atoi
  7420. // e = e * 10 + (s[i] - '0');
  7421. // while (e-- > 0)
  7422. // val *= 10;
  7423. // return val;
  7424. // }
  7425. // }
  7426. // else
  7427. // return val;
  7428. //}
  7429. //
  7430. //void cleararray(char array[], int endofdata) //clear array
  7431. //{
  7432. // int i = 0;
  7433. // while (i <= endofdata)
  7434. // {
  7435. // array[i] = '\0';
  7436. // i++;
  7437. // }
  7438. //}
  7439. //
  7440. //int getline(char s[], int lim) //stores characters into an array, ends with '\n' '\0'
  7441. //{
  7442. // int c;
  7443. // int i = 0;
  7444. // while (--lim > 0 && (c = getchar()) != EOF && c != '\n')
  7445. // s[i++] = c;
  7446. // if (c == '\n')
  7447. // s[i++] = c;
  7448. // if (c == EOF)
  7449. // return -1;
  7450. // s[i] = '\0';
  7451. // return i;
  7452. //}
  7453. //
  7454. //void cleararrayfrom_to(char array[], int from, int to) //clear array
  7455. //{
  7456. // int i = from;
  7457. // while (i <= to)
  7458. // {
  7459. // array[i] = '\0';
  7460. // i++;
  7461. // }
  7462. //}
  7463.  
  7464. //#define NUMBER 1
  7465. //
  7466. //int getop(char[]); //processes data into a number that is pushed onto a stack or an operand
  7467. //void push(double); //stores argument into values[]
  7468. //double pop(void); //returns the top value in stack values[]
  7469. //int getchx(void); //reads from operator_or_error_overread[] if it has anything, else uses getchar()
  7470. //void ungetchx(int); //stores argument in operator_or_error_overread[]
  7471. //double atofx(char[]); //converts the string op[] into a number
  7472. //void cleararray(char[], int);
  7473. //void cleararrayfrom_to(char[], int, int);
  7474. //int getline(char[], int);
  7475. //
  7476. //char getchxungetchx[MAXARRAYSIZE];
  7477. //int gi = 0;
  7478. //
  7479. //char op[MAXARRAYSIZE]; //array used to store numbers that may be negative and floating-point. Used with atof to produce a number that is pushed onto values[index]
  7480. //
  7481. //int index = 0; //index of the stack of numbers
  7482. //double values[MAXARRAYSIZE]; //stack of numbers
  7483. //
  7484. //char ungets_string[MAXARRAYSIZE]; //an array used to push back an entire line of numbers and operands onto the input
  7485. //int ungets_index = 0; //index of the ungets array
  7486. //char temparray[MAXARRAYSIZE];
  7487. //int ti = 0;
  7488. //
  7489. //char operator_or_error_overread[MAXARRAYSIZE]; //stored overread characters: 1.2+ saves +, here. Then getc() reads from here first, instead of using getchar(). Also stores everything from ungets[], ungets 'u' pushes a string onto the input using this array that getc() reads from, instead of reading with getchar()
  7490. //int index_error = 0; //index of operator_or_error_overread[]
  7491. //
  7492. //
  7493. //main()
  7494. //{
  7495. // int operator; //variable for holding a number popped from the stack of numbers values[index]
  7496. // double operator2; //second variable for holding a number popped from the stack of numbers values[index]
  7497. // double temp; //variable for holding a value temporarily
  7498. // double temp2; //variable for holding a value temporarily
  7499. //
  7500. // double a = 0; /* variables for holding values and a flag to indicate if they have been defined*/
  7501. // int a_def = NO;
  7502. // double b = 0;
  7503. // int b_def = NO;
  7504. // double x = 0;
  7505. // int x_def = NO;
  7506. // double y = 0;
  7507. // int y_def = NO;
  7508. // int undef = 0; /* variables for holding values and a flag to indicate if they have been defined*/
  7509. //
  7510. // double mrp = 0.0; //most recently printed value
  7511. //
  7512. // int placeholder = 0; //used for multiple ungets 'u' in one line of input
  7513. // int placeholder_gi = 0;
  7514. // int u = 0;
  7515. //
  7516. //Start:
  7517. // while (getline(getchxungetchx, MAXARRAYSIZE) > 0)
  7518. // {
  7519. // while ((operator = getop(op)) != '\0')
  7520. // {
  7521. // switch (operator) {
  7522. //
  7523. // case 'a': /*define and undefine variables*/
  7524. // if (a_def == NO)
  7525. // {
  7526. // if (index > 0)
  7527. // a = pop(), a_def = YES;
  7528. // else
  7529. // a = 0;
  7530. // }
  7531. // else
  7532. // push(a);
  7533. // break;
  7534. // case 'b':
  7535. // if (b_def == NO)
  7536. // b = pop(), b_def = YES;
  7537. // else
  7538. // push(b);
  7539. // break;
  7540. // case 'x':
  7541. // if (x_def == NO)
  7542. // x = pop(), x_def = YES;
  7543. // else
  7544. // push(a);
  7545. // break;
  7546. // case 'y':
  7547. // if (y_def == NO)
  7548. // y = pop(), y_def = YES;
  7549. // else
  7550. // push(a);
  7551. // break;
  7552. // case 'z': //assuming appropriate usage //undefine variable
  7553. // undef = getchar();
  7554. // switch (undef) {
  7555. // case 'a':
  7556. // a_def = NO;
  7557. // break;
  7558. // case 'b':
  7559. // b_def = NO;
  7560. // break;
  7561. // case 'x':
  7562. // x_def = NO;
  7563. // break;
  7564. // case 'y':
  7565. // y_def = NO;
  7566. // break;
  7567. // default: printf("Error: The character after z is supposed to be a variable. The variable are a, b, x, and y. The correct syntax to undefine a variable is za, zb, zx, and zy.\n");
  7568. // break;
  7569. // }
  7570. // break; /*define and undefine variables*/
  7571. //
  7572. //
  7573. //
  7574. // case NUMBER:
  7575. // push(atof(op));
  7576. // break;
  7577. // case '+':
  7578. // push(pop() + pop());
  7579. // break;
  7580. // case '*':
  7581. // push(pop() * pop());
  7582. // break;
  7583. // case '-':
  7584. // operator2 = pop();
  7585. // push(pop() - operator2);
  7586. // break;
  7587. // case '/':
  7588. // operator2 = pop();
  7589. // if (operator2 != 0.0)
  7590. // push(pop() / operator2);
  7591. // else
  7592. // printf("Error: Operator 2 is 0. Cannot divide by 0.\n");
  7593. // break;
  7594. // case '%':
  7595. // operator2 = pop();
  7596. // if (operator2 != 0)
  7597. // push((int)pop() % (int)operator2);
  7598. // else
  7599. // printf("Error: Operator 2 is 0. Cannot divide by 0.\n");
  7600. // break;
  7601. // case 'q':
  7602. // push(sin(pop()));
  7603. // break;
  7604. // case 'w':
  7605. // push(cos(pop()));
  7606. // break;
  7607. // case 'e':
  7608. // operator2 = pop();
  7609. // push(pow(pop(), operator2));
  7610. // break;
  7611. //
  7612. //
  7613. //
  7614. // case 'm': //print mrp
  7615. // printf("%f\n", mrp);
  7616. // break;
  7617. // case 'p': //print topmost value in stack values[]
  7618. // temp = pop();
  7619. // push(temp);
  7620. // printf("%f", temp);
  7621. // break;
  7622. // case 'd': //duplicate topmost value in stack values[]
  7623. // temp = pop();
  7624. // push(temp);
  7625. // push(temp);
  7626. // break;
  7627. // case 's': //swap topmost two values in stack values[]
  7628. // temp = pop();
  7629. // temp2 = pop();
  7630. // push(temp);
  7631. // push(temp2);
  7632. // break;
  7633. // case 'c': //clear values[]
  7634. // cleararray(values, index);
  7635. // index = 0;
  7636. // break;
  7637. //
  7638. //
  7639. //
  7640. // case 'u': //places everything before 'u' in the line of input where 'u' was
  7641. // ungets_string[ungets_index] = '\0';
  7642. //
  7643. // placeholder_gi = gi;
  7644. //
  7645. // while (getchxungetchx[placeholder_gi] != '\0')
  7646. // {
  7647. // temparray[ti] = getchxungetchx[placeholder_gi];
  7648. // ti++, placeholder_gi++;
  7649. // }
  7650. //
  7651. // cleararrayfrom_to(getchxungetchx, gi - 1, MAXARRAYSIZE - 1);
  7652. //
  7653. // temparray[ti] = '\0';
  7654. //
  7655. // placeholder = ungets_index -1;
  7656. // placeholder_gi = gi - 1;
  7657. // u = 0;
  7658. //
  7659. // while (u < placeholder)
  7660. // {
  7661. // getchxungetchx[placeholder_gi] = ungets_string[u];
  7662. // placeholder_gi++;
  7663. // u++;
  7664. // }
  7665. //
  7666. // ti = 0;
  7667. //
  7668. // while (temparray[ti] != '\0')
  7669. // {
  7670. // getchxungetchx[placeholder_gi] = temparray[ti];
  7671. // ti++, placeholder_gi++;
  7672. // }
  7673. //
  7674. // gi = gi - 1;
  7675. // cleararray(temparray, ti);
  7676. // ti = 0;
  7677. // break;
  7678. // case 'r': //clears ungets_string[]
  7679. // printf("Cleared ungets_string[]: %s\n", ungets_string);
  7680. // cleararray(ungets_string, ungets_index);
  7681. // printf("Current ungets_string: %s\n", ungets_string);
  7682. // ungets_index = 0;
  7683. // break;
  7684. // case 'v':
  7685. // printf("%s\n", ungets_string);
  7686. // break;
  7687. //
  7688. // case '\n': //prints the topmost value of values[], saves mrp
  7689. // mrp = pop();
  7690. // printf("\t%.8f\n", mrp);
  7691. // cleararray(getchxungetchx, gi);
  7692. // gi = 0;
  7693. // goto Start;
  7694. // break;
  7695. // case '!': //end program
  7696. // goto terminate;
  7697. // break;
  7698. // default: //error
  7699. // printf("Error: The program read a character using getchar() that was not a digit or a character with a switch case defined. The character is %s.\n", op);
  7700. // break;
  7701. // }
  7702. // }
  7703. // }
  7704. //terminate:
  7705. // return 0;
  7706. //}
  7707. //
  7708. //void push(double OperandValue) //stores argument into stack values[], else full
  7709. //{
  7710. // if (index < MAXARRAYSIZE)
  7711. // values[index++] = OperandValue;
  7712. // else
  7713. // printf("Error: Stack full. Cannot push operand value %g.\n", OperandValue);
  7714. //}
  7715. //double pop(void) //returns topmost value of values[], else error
  7716. //{
  7717. // if (index > 0)
  7718. // return values[--index];
  7719. // else
  7720. // {
  7721. // printf("Error: There are 0 operands stored in the stack containing numbers.\n");
  7722. // return 0.0;
  7723. // }
  7724. //}
  7725. //
  7726. ////getchx with I, ungetchx with D
  7727. ////array for op
  7728. //int getop(char s[]) //process characters and return to the switch with a number or a character
  7729. //{
  7730. // int i = 0;
  7731. //
  7732. // while ((s[i] = getchxungetchx[gi]) == ' ' || getchxungetchx[gi] == '\t')//skips white space by overwriting c into s[0] until an operand, operator, or error is read using getch() which reads an operand, operator, or error from getchar() overreading past any number onto a space or an operator 1.2+ or 1.2 .
  7733. // {
  7734. // ungets_string[ungets_index++] = getchxungetchx[gi];
  7735. // gi++;
  7736. // }
  7737. // if (s[i] != '\n' && s[i] != 'u')
  7738. // ungets_string[ungets_index++] = s[i]; //saves all characters into ungets_string[] that are not '\n' and 'u'. '\n' would create printing errors and 'u' would create infinite ungets operations
  7739. //
  7740. // else if (s[i] == '\n')
  7741. // {
  7742. // gi++;
  7743. // return s[i];
  7744. // }
  7745. //
  7746. // if (!isdigit(s[i]) && s[i] != '.' && s[i] != '-') //saves character operand and returns character operand
  7747. // {
  7748. // gi++;
  7749. // return s[i];
  7750. // }
  7751. //
  7752. // if (s[i] == '-' && !isdigit(getchxungetchx[gi + 1])) //saves negative '-' character and return character '-'
  7753. // {
  7754. // gi++;
  7755. // return s[i];
  7756. // }
  7757. // else if (s[i] == '-' && isdigit(getchxungetchx[gi + 1])) //saves first digit after '-'
  7758. // {
  7759. // i++, gi++;
  7760. // s[i] = getchxungetchx[gi];
  7761. // ungets_string[ungets_index++] = s[i];
  7762. // }
  7763. //
  7764. // if (isdigit(getchxungetchx[gi])) //saves number
  7765. // {
  7766. // i++;
  7767. // while (isdigit(getchxungetchx[++gi]))
  7768. // ungets_string[ungets_index++] = s[i++] = getchxungetchx[gi];
  7769. // }
  7770. //
  7771. // if (getchxungetchx[gi] == '.') //saves decimals
  7772. // {
  7773. // i++, gi++;
  7774. // ungets_string[ungets_index++] = s[i++] = getchxungetchx[gi];
  7775. // while (isdigit(getchxungetchx[++gi]))
  7776. // ungets_string[ungets_index++] = s[i++] = getchxungetchx[gi];
  7777. // }
  7778. //
  7779. // s[i] = '\0';
  7780. //
  7781. // return NUMBER;
  7782. //}
  7783. //
  7784. //int getchx(void) //if there is a value in operator_or_error_overread[] read from it, else use getchar()
  7785. //{
  7786. // return (index_error > 0) ? operator_or_error_overread[--index_error] : getchar();
  7787. //}
  7788. //void ungetchx(int operator_or_error) //if there is space in operator_or_error_overread[] store operator_or_error, else error
  7789. //{
  7790. // if (index_error >= MAXARRAYSIZE)
  7791. // printf("Error: Stack full. Cannot push character.\n");
  7792. // else
  7793. // {
  7794. // if (operator_or_error == EOF)
  7795. // operator_or_error_overread[index_error++] = '0';
  7796. // else
  7797. // operator_or_error_overread[index_error++] = operator_or_error;
  7798. // }
  7799. //}
  7800. //
  7801. //double atofx(char s[]) //convert string to floating-point number
  7802. //{
  7803. // int i = 0;
  7804. // int sign = 1;
  7805. // int val = 0;
  7806. // int power = 1;
  7807. // int e = 0;
  7808. // double exp = 0;
  7809. // if (s[i] == '-')
  7810. // {
  7811. // sign = -1;
  7812. // i++;
  7813. // }
  7814. // else if (s[i] == '+')
  7815. // i++;
  7816. // while (isdigit(s[i]))
  7817. // val = val * 10 + (s[i++] - '0');
  7818. // if (s[i] == '.')
  7819. // {
  7820. // i++;
  7821. // while (isdigit(s[i]))
  7822. // {
  7823. // val = val * 10 + (s[i++] - '0');
  7824. // power *= 10;
  7825. // }
  7826. // }
  7827. // val = sign * val / power;
  7828. // if (s[i] == 'e' || s[i] == 'E')
  7829. // {
  7830. // i++;
  7831. // if (s[i] == '-')
  7832. // {
  7833. // i++;
  7834. // while (isdigit(s[i])) //atoi
  7835. // e = e * 10 + (s[i] - '0');
  7836. // while (e-- > 0)
  7837. // val /= 10;
  7838. // return val;
  7839. // }
  7840. // else if (s[i] == '+')
  7841. // {
  7842. // i++;
  7843. // while (isdigit(s[i])) //atoi
  7844. // e = e * 10 + (s[i] - '0');
  7845. // while (e-- > 0)
  7846. // val *= 10;
  7847. // return val;
  7848. // }
  7849. // }
  7850. // else
  7851. // return val;
  7852. //}
  7853. //
  7854. //void cleararray(char array[], int endofdata) //clear array
  7855. //{
  7856. // int i = 0;
  7857. // while (i <= endofdata)
  7858. // {
  7859. // array[i] = '\0';
  7860. // i++;
  7861. // }
  7862. //}
  7863. //
  7864. //int getline(char s[], int lim) //stores characters into an array, ends with '\n' '\0'
  7865. //{
  7866. // int c;
  7867. // int i = 0;
  7868. // while (--lim > 0 && (c = getchar()) != EOF && c != '\n')
  7869. // s[i++] = c;
  7870. // if (c == '\n')
  7871. // s[i++] = c;
  7872. // if (c == EOF)
  7873. // return -1;
  7874. // s[i] = '\0';
  7875. // return i;
  7876. //}
  7877. //
  7878. //void cleararrayfrom_to(char array[], int from, int to) //clear array
  7879. //{
  7880. // int i = from;
  7881. // while (i <= to)
  7882. // {
  7883. // array[i] = '\0';
  7884. // i++;
  7885. // }
  7886. //}
  7887.  
  7888. //#define NUMBER 1
  7889. //
  7890. //int getop(char[]); //processes data into a number that is pushed onto a stack or an operand
  7891. //void push(double); //stores argument into values[]
  7892. //double pop(void); //returns the top value in stack values[]
  7893. //double atofx(char[]); //converts the string op[] into a number
  7894. //void cleararray(char[], int);
  7895. //void cleararrayfrom_to(char[], int, int);
  7896. //int getline(char[], int);
  7897. //
  7898. //char getchxungetchx[MAXARRAYSIZE];
  7899. //int gi = 0;
  7900. //
  7901. //char op[MAXARRAYSIZE]; //array used to store numbers that may be negative and floating-point. Used with atof to produce a number that is pushed onto values[index]
  7902. //
  7903. //int index = 0; //index of the stack of numbers
  7904. //double values[MAXARRAYSIZE]; //stack of numbers
  7905. //
  7906. //char ungets_string[MAXARRAYSIZE]; //an array used to push back an entire line of numbers and operands onto the input
  7907. //int ungets_index = 0; //index of the ungets array
  7908. //char temparray[MAXARRAYSIZE];
  7909. //int ti = 0;
  7910. //
  7911. //main()
  7912. //{
  7913. // int operator; //variable for holding a number popped from the stack of numbers values[index]
  7914. // double operator2; //second variable for holding a number popped from the stack of numbers values[index]
  7915. // double temp; //variable for holding a value temporarily
  7916. // double temp2; //variable for holding a value temporarily
  7917. //
  7918. // double a = 0; /* variables for holding values and a flag to indicate if they have been defined*/
  7919. // int a_def = NO;
  7920. // double b = 0;
  7921. // int b_def = NO;
  7922. // double x = 0;
  7923. // int x_def = NO;
  7924. // double y = 0;
  7925. // int y_def = NO;
  7926. // int undef = 0; /* variables for holding values and a flag to indicate if they have been defined*/
  7927. //
  7928. // double mrp = 0.0; //most recently printed value
  7929. //
  7930. // int placeholder = 0; //used for multiple ungets 'u' in one line of input
  7931. // int placeholder_gi = 0;
  7932. // int u = 0;
  7933. //
  7934. //Start:
  7935. // while (getline(getchxungetchx, MAXARRAYSIZE) > 0)
  7936. // {
  7937. // while ((operator = getop(op)) != '\0')
  7938. // {
  7939. // switch (operator) {
  7940. //
  7941. // case 'a': /*define and undefine variables*/
  7942. // if (a_def == NO)
  7943. // {
  7944. // if (index > 0)
  7945. // a = pop(), a_def = YES;
  7946. // else
  7947. // a = 0;
  7948. // }
  7949. // else
  7950. // push(a);
  7951. // break;
  7952. // case 'b':
  7953. // if (b_def == NO)
  7954. // b = pop(), b_def = YES;
  7955. // else
  7956. // push(b);
  7957. // break;
  7958. // case 'x':
  7959. // if (x_def == NO)
  7960. // x = pop(), x_def = YES;
  7961. // else
  7962. // push(a);
  7963. // break;
  7964. // case 'y':
  7965. // if (y_def == NO)
  7966. // y = pop(), y_def = YES;
  7967. // else
  7968. // push(a);
  7969. // break;
  7970. // case 'z': //assuming appropriate usage //undefine variable
  7971. // undef = getchar();
  7972. // switch (undef) {
  7973. // case 'a':
  7974. // a_def = NO;
  7975. // break;
  7976. // case 'b':
  7977. // b_def = NO;
  7978. // break;
  7979. // case 'x':
  7980. // x_def = NO;
  7981. // break;
  7982. // case 'y':
  7983. // y_def = NO;
  7984. // break;
  7985. // default: printf("Error: The character after z is supposed to be a variable. The variable are a, b, x, and y. The correct syntax to undefine a variable is za, zb, zx, and zy.\n");
  7986. // break;
  7987. // }
  7988. // break; /*define and undefine variables*/
  7989. //
  7990. //
  7991. //
  7992. // case NUMBER:
  7993. // push(atof(op));
  7994. // break;
  7995. // case '+':
  7996. // push(pop() + pop());
  7997. // break;
  7998. // case '*':
  7999. // push(pop() * pop());
  8000. // break;
  8001. // case '-':
  8002. // operator2 = pop();
  8003. // push(pop() - operator2);
  8004. // break;
  8005. // case '/':
  8006. // operator2 = pop();
  8007. // if (operator2 != 0.0)
  8008. // push(pop() / operator2);
  8009. // else
  8010. // printf("Error: Operator 2 is 0. Cannot divide by 0.\n");
  8011. // break;
  8012. // case '%':
  8013. // operator2 = pop();
  8014. // if (operator2 != 0)
  8015. // push((int)pop() % (int)operator2);
  8016. // else
  8017. // printf("Error: Operator 2 is 0. Cannot divide by 0.\n");
  8018. // break;
  8019. // case 'q':
  8020. // push(sin(pop()));
  8021. // break;
  8022. // case 'w':
  8023. // push(cos(pop()));
  8024. // break;
  8025. // case 'e':
  8026. // operator2 = pop();
  8027. // push(pow(pop(), operator2));
  8028. // break;
  8029. //
  8030. //
  8031. //
  8032. // case 'm': //print mrp
  8033. // printf("%f\n", mrp);
  8034. // break;
  8035. // case 'p': //print topmost value in stack values[]
  8036. // temp = pop();
  8037. // push(temp);
  8038. // printf("%f", temp);
  8039. // break;
  8040. // case 'd': //duplicate topmost value in stack values[]
  8041. // temp = pop();
  8042. // push(temp);
  8043. // push(temp);
  8044. // break;
  8045. // case 's': //swap topmost two values in stack values[]
  8046. // temp = pop();
  8047. // temp2 = pop();
  8048. // push(temp);
  8049. // push(temp2);
  8050. // break;
  8051. // case 'c': //clear values[]
  8052. // cleararray(values, index);
  8053. // index = 0;
  8054. // break;
  8055. //
  8056. //
  8057. //
  8058. // case 'u': //places everything before 'u' in the line of input where 'u' was
  8059. // ungets_string[ungets_index] = '\0';
  8060. //
  8061. // placeholder_gi = gi;
  8062. //
  8063. // while (getchxungetchx[placeholder_gi] != '\0')
  8064. // {
  8065. // temparray[ti] = getchxungetchx[placeholder_gi];
  8066. // ti++, placeholder_gi++;
  8067. // }
  8068. //
  8069. // cleararrayfrom_to(getchxungetchx, gi - 1, MAXARRAYSIZE - 1);
  8070. //
  8071. // temparray[ti] = '\0';
  8072. //
  8073. // placeholder = ungets_index - 1;
  8074. // placeholder_gi = gi - 1;
  8075. // u = 0;
  8076. //
  8077. // while (u < placeholder)
  8078. // {
  8079. // getchxungetchx[placeholder_gi] = ungets_string[u];
  8080. // placeholder_gi++;
  8081. // u++;
  8082. // }
  8083. //
  8084. // ti = 0;
  8085. //
  8086. // while (temparray[ti] != '\0')
  8087. // {
  8088. // getchxungetchx[placeholder_gi] = temparray[ti];
  8089. // ti++, placeholder_gi++;
  8090. // }
  8091. //
  8092. // gi = gi - 1;
  8093. // cleararray(temparray, ti);
  8094. // ti = 0;
  8095. // break;
  8096. // case 'r': //clears ungets_string[]
  8097. // printf("Cleared ungets_string[]: %s\n", ungets_string);
  8098. // cleararray(ungets_string, ungets_index);
  8099. // printf("Current ungets_string: %s\n", ungets_string);
  8100. // ungets_index = 0;
  8101. // break;
  8102. // case 'v':
  8103. // printf("%s\n", ungets_string);
  8104. // break;
  8105. //
  8106. // case '\n': //prints the topmost value of values[], saves mrp
  8107. // mrp = pop();
  8108. // printf("\t%.8f\n", mrp);
  8109. // cleararray(getchxungetchx, gi);
  8110. // gi = 0;
  8111. // goto Start;
  8112. // break;
  8113. // case '!': //end program
  8114. // goto terminate;
  8115. // break;
  8116. // default: //error
  8117. // printf("Error: The program read a character using getchar() that was not a digit or a character with a switch case defined. The character is %s.\n", op);
  8118. // break;
  8119. // }
  8120. // }
  8121. // }
  8122. //terminate:
  8123. // return 0;
  8124. //}
  8125. //
  8126. //void push(double OperandValue) //stores argument into stack values[], else full
  8127. //{
  8128. // if (index < MAXARRAYSIZE)
  8129. // values[index++] = OperandValue;
  8130. // else
  8131. // printf("Error: Stack full. Cannot push operand value %g.\n", OperandValue);
  8132. //}
  8133. //double pop(void) //returns topmost value of values[], else error
  8134. //{
  8135. // if (index > 0)
  8136. // return values[--index];
  8137. // else
  8138. // {
  8139. // printf("Error: There are 0 operands stored in the stack containing numbers.\n");
  8140. // return 0.0;
  8141. // }
  8142. //}
  8143. //
  8144. ////getchx with I, ungetchx with D
  8145. ////array for op
  8146. //int getop(char s[]) //process characters and return to the switch with a number or a character
  8147. //{
  8148. // int i = 0;
  8149. //
  8150. // while ((s[i] = getchxungetchx[gi]) == ' ' || getchxungetchx[gi] == '\t')//skips white space by overwriting c into s[0] until an operand, operator, or error is read using getch() which reads an operand, operator, or error from getchar() overreading past any number onto a space or an operator 1.2+ or 1.2 .
  8151. // {
  8152. // ungets_string[ungets_index++] = getchxungetchx[gi];
  8153. // gi++;
  8154. // }
  8155. // if (s[i] != '\n' && s[i] != 'u')
  8156. // ungets_string[ungets_index++] = s[i]; //saves all characters into ungets_string[] that are not '\n' and 'u'. '\n' would create printing errors and 'u' would create infinite ungets operations
  8157. //
  8158. // else if (s[i] == '\n')
  8159. // {
  8160. // gi++;
  8161. // return s[i];
  8162. // }
  8163. //
  8164. // if (!isdigit(s[i]) && s[i] != '.' && s[i] != '-') //saves character operand and returns character operand
  8165. // {
  8166. // gi++;
  8167. // return s[i];
  8168. // }
  8169. //
  8170. // if (s[i] == '-' && !isdigit(getchxungetchx[gi + 1])) //saves negative '-' character and return character '-'
  8171. // {
  8172. // gi++;
  8173. // return s[i];
  8174. // }
  8175. // else if (s[i] == '-' && isdigit(getchxungetchx[gi + 1])) //saves first digit after '-'
  8176. // {
  8177. // i++, gi++;
  8178. // s[i] = getchxungetchx[gi];
  8179. // ungets_string[ungets_index++] = s[i];
  8180. // }
  8181. //
  8182. // if (isdigit(getchxungetchx[gi])) //saves number
  8183. // {
  8184. // i++;
  8185. // while (isdigit(getchxungetchx[++gi]))
  8186. // ungets_string[ungets_index++] = s[i++] = getchxungetchx[gi];
  8187. // }
  8188. //
  8189. // if (getchxungetchx[gi] == '.') //saves decimals
  8190. // {
  8191. // i++, gi++;
  8192. // ungets_string[ungets_index++] = s[i++] = getchxungetchx[gi];
  8193. // while (isdigit(getchxungetchx[++gi]))
  8194. // ungets_string[ungets_index++] = s[i++] = getchxungetchx[gi];
  8195. // }
  8196. //
  8197. // s[i] = '\0';
  8198. //
  8199. // return NUMBER;
  8200. //}
  8201. //
  8202. //double atofx(char s[]) //convert string to floating-point number
  8203. //{
  8204. // int i = 0;
  8205. // int sign = 1;
  8206. // int val = 0;
  8207. // int power = 1;
  8208. // int e = 0;
  8209. // double exp = 0;
  8210. // if (s[i] == '-')
  8211. // {
  8212. // sign = -1;
  8213. // i++;
  8214. // }
  8215. // else if (s[i] == '+')
  8216. // i++;
  8217. // while (isdigit(s[i]))
  8218. // val = val * 10 + (s[i++] - '0');
  8219. // if (s[i] == '.')
  8220. // {
  8221. // i++;
  8222. // while (isdigit(s[i]))
  8223. // {
  8224. // val = val * 10 + (s[i++] - '0');
  8225. // power *= 10;
  8226. // }
  8227. // }
  8228. // val = sign * val / power;
  8229. // if (s[i] == 'e' || s[i] == 'E')
  8230. // {
  8231. // i++;
  8232. // if (s[i] == '-')
  8233. // {
  8234. // i++;
  8235. // while (isdigit(s[i])) //atoi
  8236. // e = e * 10 + (s[i] - '0');
  8237. // while (e-- > 0)
  8238. // val /= 10;
  8239. // return val;
  8240. // }
  8241. // else if (s[i] == '+')
  8242. // {
  8243. // i++;
  8244. // while (isdigit(s[i])) //atoi
  8245. // e = e * 10 + (s[i] - '0');
  8246. // while (e-- > 0)
  8247. // val *= 10;
  8248. // return val;
  8249. // }
  8250. // }
  8251. // else
  8252. // return val;
  8253. //}
  8254. //
  8255. //void cleararray(char array[], int endofdata) //clear array
  8256. //{
  8257. // int i = 0;
  8258. // while (i <= endofdata)
  8259. // {
  8260. // array[i] = '\0';
  8261. // i++;
  8262. // }
  8263. //}
  8264. //
  8265. //int getline(char s[], int lim) //stores characters into an array, ends with '\n' '\0'
  8266. //{
  8267. // int c;
  8268. // int i = 0;
  8269. // while (--lim > 0 && (c = getchar()) != EOF && c != '\n')
  8270. // s[i++] = c;
  8271. // if (c == '\n')
  8272. // s[i++] = c;
  8273. // if (c == EOF)
  8274. // return -1;
  8275. // s[i] = '\0';
  8276. // return i;
  8277. //}
  8278. //
  8279. //void cleararrayfrom_to(char array[], int from, int to) //clear array
  8280. //{
  8281. // int i = from;
  8282. // while (i <= to)
  8283. // {
  8284. // array[i] = '\0';
  8285. // i++;
  8286. // }
  8287. //}
  8288.  
  8289. //int getopwithoutungetch(char s[]) //getop without ungetch
  8290. //{
  8291. // int c;
  8292. // int d;
  8293. // int i = 0;
  8294. // static int ungetch = 0;
  8295. // static int u = 0;
  8296. //
  8297. // if (u == 1)
  8298. // {
  8299. // s[i] = ungetch;
  8300. // }
  8301. // else
  8302. // {
  8303. // while ((s[i] = c = getch()) == ' ' || c == '\t') //skips white space by overwriting c into s[0] until an operand, operator, or error is read using getch() which reads an operand or error from getchar() overreading past a number onto an operator 123.456+.
  8304. // ;
  8305. // }
  8306. // s[i++] = '\0';
  8307. // if (!isdigit(c) && c != '.' && c != '-')
  8308. // return c;
  8309. // if (c == '-' && !isdigit(d = getch()))
  8310. // {
  8311. // ungetch = d;
  8312. // return c;
  8313. // }
  8314. // else if (c == '-')
  8315. // s[i++] = '-';
  8316. // if (isdigit(c))
  8317. // while (isdigit(s[i++] = c = getch()))
  8318. // ;
  8319. // if (c == '.')
  8320. // {
  8321. // s[i++] = c;
  8322. // while (isdigit(s[i++] = c = getch()))
  8323. // ;
  8324. // }
  8325. // s[i] = '\0';
  8326. // if (c != EOF)
  8327. // {
  8328. // ungetch = c;
  8329. // u = 1;
  8330. // }
  8331. // return NUMBER;
  8332. //}
  8333.  
  8334. //void recursive_itoa(int n, char s[])
  8335. //{
  8336. // long long int pn = 0;
  8337. // char digit;
  8338. // static int i = 0;
  8339. //
  8340. // if (n < 0)
  8341. // {
  8342. // pn = -n;
  8343. // s[i++] = '-';
  8344. // }
  8345. // else
  8346. // pn = n;
  8347. //
  8348. // if (pn / 10 > 0)
  8349. // {
  8350. // digit = (pn % 10) - '0'; //digit 3 2
  8351. // pn /= 10; //123 12
  8352. // recursive_itoa(pn, s);
  8353. // }
  8354. // else
  8355. // digit = (pn % 10) - '0'; // 1 1
  8356. //
  8357. // s[i++] = digit;
  8358. //}
  8359.  
  8360. //void recursive_reverse(char s[])
  8361. //{
  8362. // static int i = 0;
  8363. // static int j = 0;
  8364. // char character;
  8365. //
  8366. // while (s[i] != '\0' && s[i] != EOF)
  8367. // {
  8368. // character = s[i];
  8369. // i++;
  8370. // recursive_reverse(s);
  8371. // }
  8372. //
  8373. // if (s[i] == '\0' || s[i] == EOF)
  8374. // ;
  8375. // else
  8376. // s[j++] = character;
  8377. //}
  8378.  
  8379. //#define swap(t, x, y) t temp = x, x = y, y = temp;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement