Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Files: balance.h: #include #include #define MAX_LEN 1000 int check(char input[]); balance_checker.c: #include balance.h char getword(char word[], int limit){ char c; int i = 0; while(i

image text in transcribed

image text in transcribed

Files:

balance.h:

#include #include #define MAX_LEN 1000 int check(char input[]);

balance_checker.c:

#include "balance.h" char getword(char word[], int limit){ char c; int i = 0; while(i

check.c:

#define BUFSIZE 1000 #include static char buf[BUFSIZE];//buffer for opening symbols

static int bufp;/ext free position in buf

void push(char c){ buf[bufp] = c; bufp++; } char pop(void){ if(is_empty()) return '\0'; bufp--; return buf[bufp]; } char peek (void){ return buf[bufp - 1]; } int is_empty(){ return !bufp; } int size(){ return bufp; } int check(char input[]){ //extern char opening_symbol[]; //extern char closing_symbol[]; //your code here... printf("Checking %s ", input); bufp = 0;//empty out the stack! int len = strlen(input); for(int i = 0; i

makefile:

CC=gcc CFLAGS=-I. -g -w DEPS= balance.h OBJ = balance_checker.o pair.o check.o %.o: %.c $(DEPS) $(CC) -c -o $@ $

most of the program is already finished. the pair.c file needs work. Program written in C

In this assignment, you will write a program that checks the input string to see if it is made of balanced parentheses. Balanced parentheses means that each opening symbol has a corresponding closing symbol and the pairs of parentheses are properly nested. 1 Program Input Commands There are three valid commands for your program: - quit : ends the program w/o printing anything on stdout. - check STR whether it is balanced or not. Please note that STR cannot contain a new line character. Program outputs "balanced" or "not balanced". - pair o0,c0o1,c1o2,c2on,cn : where each pair of symbols oi,ci represents an opening symbol/character (oi) and its corresponding closing symbol/character (ci). By default, the program only checks the balance of parentheses. But, for example, in order to check the balance of strings made of parentheses, brackets and curly brackets (braces), the user needs to enter the following command: pair (,) 1,/{, command, we assume that no duplicate symbols are entered by the user, each opening symbol and its corresponding symbol are separated by only a single comma, and any two adjacent pairs are separated by a single white space character. Also, the program needs to reject the usage of comma, new-line, tab, and white-space characters as an opening or closing symbol. Finally, you can assume that user does not enter more than 50 pairs in each pair command. Program prints nothing to stdout as the result of this command. 2 Functions of Your Program Your program may use different functions. However, it must have the following three functions in separate files: - int main(): The main function which must be stored in balance_checker.c file. - int check(char str[)) : The check function returns 1 if the input str contains a balanced string and returns 0 otherwise. Please note that this function works with the mostrecently given list of pairs and ignores all other characters in the input string. This function must be stored in check.c file. Also, make sure to use a stack to check the balance of opening and closing symbols in this function. - void pair(char list[l): The pair function, which needs to be stored in pair.c file, gets the list of opening and closing symbols, the way entered by the user, and stores them in two external char arrays called opening_symobls and closing_symbols. These arrays need to be external so that they can be accessible by the check function stored in check.c file. Also, these arrays must be defined as oversize arrays of capacity equal to 51. To show their true size, you can place a NULL character after the last symbol they store. For example, if list is "(,) l,{,}",thenthearrayslooklikethis: 3 Submissions You need to submit a .zip file compressing the followings: - balance_checker.c - check.c - pair.c - other .c files (if you have any) - balance.h - makefile which organizes the compilation process of your program. Use the word "balance" to name the executable of your program. - snapshot of gdb program running the main function of your program line-by-line (.jpg or .png files only)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions