Question: Code in C DIRECTIONS: C balanced_provided.c X C balanced_provided.c 1 #include 2 #include 3 #include 4 5 // Struct to hold the expected close brace

Code in C

Code in C DIRECTIONS: 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

DIRECTIONS:

int main(int argc, char* argv[]) 12 { 13 14 FILE* fp =

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 testo.txt X tests > Z testo.txt 1 (2) test1.txt X x tests ) test1.txt 1 test2.txt X tests > 5 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 '', '). I, and "}" without any intervening open parentheses, brackets, or braces For example, these are balanced expressions: ({003) But these are not: (0 [1 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/test.txt Your program should check whether the expression in the input file is balanced, and then print to the command line "yes" if the expression is balanced, and "no" if it is not. The corresponding expected outputs are in the answers directory: answers/answer.txt

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!