I need to write a C++ program. I'm usually pretty decent with C++ but with this one I'm lost. I have to write a program that basically checks to make sure that the braces creating a block in a cpp file are balanced. I'm not looking for anyone to write it for me but I was hoping someone could help me out or point me in the right direction. I've attached the requirements to the post. I don't know how to check for balanced braces and where I REALLY get lost is how to reposition the braces as stated and how to ignore ones not creating a block.
mumblejum
0
Newbie Poster
Recommended Answers
Jump to PostCreate a counter of how many "levels" of braces you are in. What do you mean by reposition? To see if they are part of a block, look at the statement before the opening brace. If it is a for loop, if statement, etc. then it is valid.
Jump to PostAdditional to death_oclock, you will need to pass comments and string literals. Since,
/* {{ */
and"Some brackets {{{{"
and'{'
are do not need to be in the counter.Other than that you need to check that you don't go below zero.
i.e.
All 6 Replies
death_oclock
103
Posting Whiz
StuXYZ
731
Practically a Master Poster
mumblejum
0
Newbie Poster
StuXYZ
731
Practically a Master Poster
mumblejum
0
Newbie Poster
StuXYZ
731
Practically a Master Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.