Advertisement
colonel-top

Brackets Finder Bug

Aug 23rd, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define MAX_BRACK 65500
  5. //Defining Path and variable//
  6. int a[MAX_BRACK],top;
  7. char filepath[256] ="";
  8. int currentline = 0;
  9. int openbrack,closebrack = 0;
  10. //Defining Path and variable//
  11. void getfilename();
  12. void check();
  13. void pop();
  14. void credits();
  15. void push(int valueofline);
  16. void getfilename()
  17. {
  18. printf("Please insert File path ");
  19. scanf("%s",&filepath);
  20. printf("Read filepath is %s done\n",filepath);
  21. printf("Reading ...\n\n");
  22. printf("Finding Missing Brackets (Not closed) \n\n");
  23. }
  24. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  25. int main ()
  26. {
  27. credits();
  28. getfilename();
  29. FILE *filereader;
  30. filereader = fopen(filepath,"r");
  31. char tmpline[256];
  32. while(fgets(tmpline,sizeof(tmpline),filereader))
  33. {
  34. currentline++;
  35. if(strstr(tmpline,"{"))
  36. {
  37. push(currentline);
  38. openbrack++;
  39. }
  40. if(strstr(tmpline,"}"))
  41. {
  42. pop();
  43. closebrack++;
  44. }
  45.  
  46. }
  47. printf("Number of Open Bracklets = %d\n",openbrack);
  48. printf("Number of Closed Bracklets = %d\n\n",closebrack);
  49.  
  50. if(openbrack == closebrack)
  51. {
  52. printf("Code Perfect No Bracket Missed\n");
  53. getchar();
  54. }
  55. if(openbrack != closebrack)
  56. {
  57. //print stack
  58. for (int i = 1; i <=top ; i++)
  59. {
  60. printf("Problem Brackets not close , start at Line %d\n",a[i]);
  61.  
  62. }
  63.  
  64. }
  65. }
  66. void push (int valueofline)
  67. {
  68. if(top == MAX_BRACK)
  69. {
  70. printf("Overflow");
  71. }
  72. else
  73. {
  74. top=top+1;
  75. a[top] = valueofline;
  76. }
  77. }
  78. void pop ()
  79. {
  80. if(top == -65000 )
  81. {
  82. printf("Underflow");
  83. }
  84. else
  85. {
  86. top=top-1;
  87. }
  88. }
  89.  
  90. void credits()
  91. {
  92. printf("---------------------------------------------------\n");
  93. printf("---------------------------------------------------\n");
  94. printf("-=====--=====--=------=====--==---=--=====--=------\n");
  95. printf("-=------=---=--=------=---=--=-=--=--=------=------\n");
  96. printf("-=------=---=--=------=---=--=--=-=--=====--=------\n");
  97. printf("-=------=---=--=------=---=--=---==--=------=------\n");
  98. printf("-=====--=====--=====--=====--=----=--=====--=====--\n\n\n");
  99. printf("---------------------------------------------------\n");
  100. printf("---------------------------------------------------\n");
  101. printf("Bracklets Checker By Colonel \n\n\n");
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement