0

Assume that a language uses /* and */ pair for comments.Write a C program to check for balanced /* and */ pair in a given text file.Use pointer implementation of the data structure.

5
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by WaltP
0

Fine, I'll assume that you missed all the posts which tell you to post what you tried, and that we don't give you free homework answers just because you've mastered "ctrl-c" and "ctrl-v".

0

Once you get round to the actual assignment you might want to look at using a stack or some other similiar datastructure thereof.

0

Why stack? Why "pointer implementation of the data structure"?
All you need: fgetc(f) to read a file char by char plus a level counter plus a simple logic:

search '/'...
if the next char is '*' then comment started, search '*' ...
and scan again...

... and so on.
Start from a simplest scanner (without inner comments counter)...

0

>Why stack?

Why? Because it would probably be the simplest solution for finding matching pair comments, but then again there are many ways to skin a cat.

0

Since comments cannot be nested, a stack really is not necessary. A simple flag would suffice. Although a stack would be really helpful if you are looking for braces/parens/etc, things that can be nested.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.