File program which gives output induntation code when we call that file actualy it was uninduntationed before

TrustyTony commented: Do not mass post without showing honest effort -3

Recommended Answers

All 8 Replies

Is induntation legal in your country?

Daniweb is not a homework service. Please make an honest attempt to solve the problem yourself, then ask specific questions if you need help.

As a piece of advice, I can suggest this: assuming that the language you are indenting is C (or one with a similar block syntax, such as Java or C++), then the simplest solution is:

set the indent amount to four
set the indentation level to zero
for the length of the file:
    read the next char
    if the char is a newline:
        insert the newline
        insert (indent amount * indentation level) spaces
    else if the char is a whitespace:
        discard it; 
    else if the char is an open brace:
        insert a newline
        insert the open brace
        increment the indent level by one
        insert a newline
        insert (indent amount * indentation level) spaces
    else if the char is a close brace:
        insert a newline
        decrement the indent level by one
        insert close brace
        insert a newline
        insert (indent amount * indentation level) spaces
    else:
        insert the char as is

if indentation level is still more than zero, emit an error message

Now, this is just a rough method, and doesn't properly handle some edge cases (e.g., struct definitions), but it should be enough to get started with.

i tried it . . . In condition i dont no how to put 1st flower braces in 1st and next flower braces 4 space after

post what you tried, we don't have crystle balls.

flower braces?

() these are called parentheses -- or parens to those in the business. (we're lazy)
[] these are square brackets, or for us lazies, just brackets
{} these are curly brackets/braces, know simply as braces in the industry.

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.