im intending to make a brackets checking code that will check some code and look if there's any brackets mistakes in it,
i started like this :
#include<stdio.h>
int i=0;
int isPaired(char c) /*checks if bracket matches*/
{
if (c == '}' && s[--i] == '{')
return 1;
if (c == ']' && s[--i] == '[')
return 1;
if (c == ')' && s[--i] == '(')
return 1;
else
return 0;
}
int main()
{
int c;
char s[100];
while((c=getchar())!=EOF)
{
for (;c!='\n',c!=EOF;c=getchar())
{
s[i]=c;
}
c=getchar();
if (c=='\"')
if (c == '{' || c == '[' || c == '(')
{
s[i]=c;
++i;
}
if (c == '}' || c == ']' || c == ')')
if (s[i]=!'\n' && isPaired(c))
{
s[i-1]='\0';
--i;
}
}
return 0;
}
the task i got is : that i need to check only for brackets mistakes in the code that this program is gonna run on and print out the sentence which the mismatched bracket is at.
and sentence size is no more than 100 characters, in addition to that, every couple of " () " and " [] " brackets are positioned in the same sentence
and ofc exlcuding brackets that's commented or like ")"
may i have someone's guidance...
one thing i know is that i should store the whole sentence in an array thats where im stuck at and dont know how to continue..