[ create a new paste ] login | about

Link: http://codepad.org/5R3v8v7I    [ raw code | output | fork ]

C, pasted on Mar 17:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include "Singly-LinkedList.c"
#define MAX 30

int top=-1;
int stack[MAX];

void push(char);
char pop();
int match(char a,char b);
int check(char []);

int main()
{
        SN *List=NULL;
        FILE *fn;
        fn=fopen("balanced.txt","r");
        if(fn==NULL){
        return 1;
}
	char exp[MAX];
	int valid;
	valid=check(exp);
	if(valid==1)
        return 1;
	else
		return 0;
}
int check(char exp[] )
{
	int i;
	char temp;
	for(i=0;i<strlen(exp);i++)
	{
		if(exp[i]=='(' || exp[i]=='{' || exp[i]=='[')
			push(exp[i]);
		if(exp[i]==')' || exp[i]=='}' || exp[i]==']')
			if(top==-1)
			{
				return 0;
			}
			else
			{
				temp=pop();
				if(!match(temp, exp[i]))
				{
					printf("%c and %c\n",temp,exp[i]);
					return 0;
				}
			}
	}
	if(top==-1)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
int match(char a,char b)
{
	if(a=='[' && b==']')
		return 1;
	if(a=='{' && b=='}')
		return 1;
	if(a=='(' && b==')')
		return 1;
	return 0;
}
void push(char item)
{
	if(top==(MAX-1))
	{
		return;
	}
	top=top+1;
	stack[top]=item;
}

char pop()
{
	if(top==-1)
	{
		exit(1);
	}
	return(stack[top--]);
}


Output:
1
2
3
4
5
6
Line 30: error: Singly-LinkedList.c: No such file or directory
In function 'main':
Line 17: error: 'SN' undeclared (first use in this function)
Line 17: error: (Each undeclared identifier is reported only once
Line 17: error: for each function it appears in.)
Line 17: error: 'List' undeclared (first use in this function)


Create a new paste based on this one


Comments: