Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define MAX_BRACK 65500
- //Defining Path and variable//
- int a[MAX_BRACK],top;
- char filepath[256] ="";
- int currentline = 0;
- int openbrack,closebrack = 0;
- //Defining Path and variable//
- void getfilename();
- void check();
- void pop();
- void credits();
- void push(int valueofline);
- void getfilename()
- {
- printf("Please insert File path ");
- scanf("%s",&filepath);
- printf("Read filepath is %s done\n",filepath);
- printf("Reading ...\n\n");
- printf("Finding Missing Brackets (Not closed) \n\n");
- }
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- int main ()
- {
- credits();
- getfilename();
- FILE *filereader;
- filereader = fopen(filepath,"r");
- char tmpline[256];
- while(fgets(tmpline,sizeof(tmpline),filereader))
- {
- currentline++;
- if(strstr(tmpline,"{"))
- {
- push(currentline);
- openbrack++;
- }
- if(strstr(tmpline,"}"))
- {
- pop();
- closebrack++;
- }
- }
- printf("Number of Open Bracklets = %d\n",openbrack);
- printf("Number of Closed Bracklets = %d\n\n",closebrack);
- if(openbrack == closebrack)
- {
- printf("Code Perfect No Bracket Missed\n");
- getchar();
- }
- if(openbrack != closebrack)
- {
- //print stack
- for (int i = 1; i <=top ; i++)
- {
- printf("Problem Brackets not close , start at Line %d\n",a[i]);
- }
- }
- }
- void push (int valueofline)
- {
- if(top == MAX_BRACK)
- {
- printf("Overflow");
- }
- else
- {
- top=top+1;
- a[top] = valueofline;
- }
- }
- void pop ()
- {
- if(top == -65000 )
- {
- printf("Underflow");
- }
- else
- {
- top=top-1;
- }
- }
- void credits()
- {
- printf("---------------------------------------------------\n");
- printf("---------------------------------------------------\n");
- printf("-=====--=====--=------=====--==---=--=====--=------\n");
- printf("-=------=---=--=------=---=--=-=--=--=------=------\n");
- printf("-=------=---=--=------=---=--=--=-=--=====--=------\n");
- printf("-=------=---=--=------=---=--=---==--=------=------\n");
- printf("-=====--=====--=====--=====--=----=--=====--=====--\n\n\n");
- printf("---------------------------------------------------\n");
- printf("---------------------------------------------------\n");
- printf("Bracklets Checker By Colonel \n\n\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement