Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write code in C Test cases: Directions: C balanced_provided.c X C balanced_provided.c 1 #include 2 #include 3 #include 4 5 // Struct to hold the

Write code in C

image text in transcribed

Test cases:

image text in transcribed image text in transcribed

Directions:

image text in transcribed

C balanced_provided.c X C balanced_provided.c 1 #include 2 #include 3 #include 4 5 // Struct to hold the expected close brace character and a pointer to the next element. 6 struct element { 7 char close; 8 struct element* next; 9 }; 10 11 int main(int argc, char* argv[]) 12 { 13 14 FILE* fp = fopen(argv[1], "r"); 15 if (!fp) { 16 perror("fopen failed"); 17 return EXIT_FAILURE; 18 } 19 20 bool balanced = true; 21 22 char buff; 23 while ( fscanf(fp,"%c", &buff)==1 ) { 24 } 25 26 printf ( balanced ? "yes" : "no" ); 27 fclose(fp); 28 return 0; 29 } 30 test1.txt X tests > 3 test1.txt 1 test2.txt X tests > test2.txt 1 ({>(){}}) You may have noticed that your favorite text editor or integrated development environment (IDE) can help you check if open parentheses, brackets, and braces are properly closed. That is, whether each open ''; ')', ], and '}' without any intervening open parentheses, brackets, or braces. For example, these are balanced expressions: ({(){}}) But these are not: ({) [] Your task in this part of the assignment is to write a C program using structs and pointers to build a stack data structure, and use that stack to check whether a string is properly balanced. Your program should take as a command line input the path to an input file: /balanced tests/testo.txt program should check whether expression in the input file is balanced, and then print to the command line "yes" if the expression is balanced, | "no t is not

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions