~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

gave in quickly.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

clean

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You forgot to close a double quote and main doesn't return void (atleast not in C/C++). Other than that the code really is good to go... ;)

I think this should be better moved to the Geek' Lounge.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

How about showing us what you have done so far ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

*hint* Maybe this thread can serve as some inspiration to some of you guys to participate in future DaniWeb competitions.

*Wish* we had time for that... ;)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

file

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

getchar is a standard C /C++ functiona used for getting data from the standard input stream (in normal cases keyboard). It is buffered in the sense it does not see the characters unless the user presses the return key. Since we want to prevent the console window from disappearing after the program execution, we put it at the end of the program before the return statement if any is present.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

hi ,
ok tell me is there anyway to get the source file back? that file was in a USB and deleted from it.

As far as writing the program is concerned, you can be rest asssured that NO ONE would write the program for you. Any more threads on the same topic and I will make sure they are deleted and you are infracted.

If its really that precious to you and if you are not lying about the file being deleted, recovery softwares is what you need right now.

Download any of the demo versions and see if those things can detect the deleted files and if so, buy the software. Best of luck.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

His name is 'good old Ancient Dragon'... :D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Possible in WinAPI if you know how to display images and make applications which are windowless(only an image in the center of the screen). Though considering that you are a beginner it would make no sense trying to jump to WinAPI before getting the C++ basics right.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Sleep while you can, before we ban, your good old Sandman !

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You must use ==, or you'll end up with a condition that never changes.

Oh it changes alright, when the expression or L value on the RHS becomes zero. Try it out...

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Nope, I wrote my own self.

Then you must surely be frequenting google groups...:eek:

what the heack this hole thred didnt eaven make sence to me????????

Its okay, it happens to even me sometimes, but I jump in and try to make the thread more nonsensical...:twisted:

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Like I said before, trimming the string before processsing it is the way to go in your case. After trimming the string, if its length is zero (check only for length and not the other two), then flip the binary flag.

Maybe something like this: (not tested)

void leftTrim(string& inStr, const string delimiters = " \t\n\r\v\f")
{
    string::size_type pos = inStr.find_first_not_of(delimiters);
    inStr.erase(0, pos);
}

int main ()
{
    string line;
    bool flag = true;
    ifstream inFile("test.txt");
    ofstream outFile("output.txt");
    while(getline(inFile, line))
    {
        leftTrim(line);
        if(line.size() == 0)
        {
            flag = true;
            continue;   //skip current line and move to next one
        }
        if(flag)    //if a new paragraph is afoot
        {
            outFile << endl << "    " << line << endl;
            flag = false;
        }
        else        //its a normal line
        {
            outFile << line << endl;
        }
    }
    //close the streams and wait for keypress
    inFile.close();
    outFile.close();
    getchar ();
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Don't forget to consider the following situations:

• The blank lines may be composed of only spaces. You might need to write a trim function which first trims the lines read and then processes them.

• The first line can be a non blank requiring you to initialize the flag accordingly.

The trim function can be as simple as (not my function):

#include <string> 
 
const std::string whiteSpaces( " \f\n\r\t\v" ); 
 
void trimRight( std::string& str, 
       const std::string& trimChars = whiteSpaces ) 
 { 
    std::string::size_type pos = str.find_last_not_of( trimChars ); 
    str.erase( pos + 1 ); 
 
} 
 

void trimLeft( std::string& str, 
       const std::string& trimChars = whiteSpaces ) 
 { 
    std::string::size_type pos = str.find_first_not_of( trimChars ); 
    str.erase( 0, pos ); 
 } 
 

void trim( std::string& str, const std::string& trimChars = whiteSpaces ) 
 { 
    trimRight( str, trimChars ); 
    trimLeft( str, trimChars ); 
 }
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

system function calls in C / C++ invoke the operating system functionality (here cls ) so the context has to be changed and control be handed from the currently running program to the Operating System to invoke the clear screen function.

Using the method posted by Joey won't invoke OS functions and hence even though it looks a bit length, its performance is way better than the system call.

Read this.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

being a gentle

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

meaning of life - perils of death

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Every morning - Sugar Ray

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Heh, I have seen that before...yeah Google Groups... :D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes I believe so...marking this as solved.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Aurora Borealis - The superunknown

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

One last breath - Creed

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Now is the time, attack !!

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I guess each of the members were allowed to have custom titles way back when Daniweb was not what it is now. Or maybe they were moderators once and stepped down when there were no Team Colleagues titles.

Once again, Dani would be in a better position to provide a perfect answer.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Oh how I envy you... :D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I wonder what BS here stands for... ;)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

which strained my

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

is cannibalism. Don't

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I'm sorry I guess I don't understand the rules of this game. I appologize.

Oh don't worry, go to the first post of this thread to read the rules. And btw, happy spamming. :D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

delight - polar lights

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

She loves me not - Papa Roach

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Looks good though I would have used strncmp to make the task more simpler. Just one statement inside the loop and you are good to go.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> They're special.
Nah, they are white hat spammers... :D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

How would you account for those millions of lines of code which use the old C functions, wrapped up in the new standard namespace? And like I pointed out getchar IS C++ otherwise it wouldn't have been included in the C++ standard namespace. Call it backward compatibility if you like, but thats how the situation stands.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The good thing about C / C++ is its flexibility and its the flexibility which kills the beginners. You can as well mix fgets and cin >> and still get away with it, no problems as such.

Oh and btw, getchar is C++ . Just include cstdio and you are good to go. The fact that getchar is included in the standard namespace makes it a C++ standard function. Call it backward compatibility or consideration for C programmers if you want, but IMHO getchar is C++. If you will notice C++ has no direct character manipulation and processing functions. The header cstdlib , ctype and cstring seem to do that job pretty well... ;)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

getchar and getche functions just read a character, they serve no purpose in detecting when a key was pressed. You need to look into the kbhit function which detects keypresses and then read the character using getchar .

Read this. but mind you that the function is highly platform and compiler dependent.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

an easy way

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

heaven. But still

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hello there my friend, welcome to Daniweb. :D

And btw, welcome to the party... ;)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> In C. It's not a good idea to use that in C++, use cin.get() instead.

Any good reason to back that up ? ;)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I guess only Moderators, Sponsors and Team Colleagues get their own custom title... :D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Here you go : ooerhffs

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Love hurts - Nazareth

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Victory has a sweet smell.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

the outer ring

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

the only possible

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

while

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

christmas gifts - santa claus

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Considering that you have already declared using namespace std at the top of your code, the complicated statement becomes cin.ignore(numeric_limits<streamsize>::max(), '\n') ;

Not so complicated, is it ? ;) But even so please make the changes since we want publication quality tutorials and we don't need the magic numbers to mar that.

> I wanted to keep the tutorial relatively simple, so I didn't really cover input validation.
No problem as such, include the code which I pasted whenever you think its appropriate. Just wanted to let you know.

And last but not the least, really good tutorial. I am waiting for the next one in the series... ;)