Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Wrox Announcements and Feedback > All Other Wrox Books
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
All Other Wrox Books Do you have a question about a Wrox book that isn't listed anywhere on p2p.wrox.com or where the forum is locked? Here's a forum to post questions about any other Wrox book so that other readers or one of the authors can help you with your questions. IF YOU ARE LOOKING FOR CODE DO NOT ASK "Where can I find the code for this book?" That question is answered here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the All Other Wrox Books section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 4th, 2003, 11:43 AM
Registered User
 
Join Date: Jun 2003
Location: Carlsbad, CA, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ivor Horton's Beginning C++

Hi all,
Program 7.5 - Page 244
it compiles but it returns undesirable results.


Typos checked a million times and it has none.
Anybody experienced this problem before?

Thanks in advance.
  #2 (permalink)  
Old June 21st, 2003, 11:07 PM
Authorized User
 
Join Date: Jun 2003
Location: Colgate, WI, USA.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Ammiel Send a message via AIM to Ammiel Send a message via MSN to Ammiel
Default

Hi odie,

I typed up the example on Microsoft Visual C++ 6.0 and it didn't give me any errors, and the example worked as shown. Perhaps your using a different compiler? Likeliness is your using a GCC relative such as MingW if your on Windows... I'll try compiling in Dev-C++ and post the results.

Yep, the code seems to be 100% portable, you probably missed a line of code or something.

Code:
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string text;
    const string separators = " ,.\"\n";
    const int max_words = 1000;
    string words[max_words];
    string *pwords[max_words];

    cout <<  endl << "Enter a string terminated by #:" << endl;
    getline(cin, text, '#');

    int start = text.find_first_not_of(separators);
    int end = 0;
    int word_count = 0;
    while(start != string::npos && word_count < max_words)
    {
        end = text.find_first_of(separators, start + 1);
        if (end == string::npos)
            end = text.length();
        words[word_count] = text.substr(start, end - start);
        pwords[word_count] = &words[word_count];
        word_count++;

        start = text.find_first_not_of(separators, end + 1);
    }

    int lowest = 0;

    for(int j = 0; j < word_count - 1; j++)
    {
        lowest = j;

        for(int i = j + 1; i < word_count; i++)
            if(*pwords[i] < *pwords[lowest])
                lowest = i;

        if(lowest != j)
        {
            string* ptemp = pwords[j];
            pwords[j] = pwords[lowest];
            pwords[lowest] = ptemp;
        }
    }

    for(int i = 0; i < word_count ; i++)
        cout << endl << *pwords[i];

    cout << endl;
    return 0;
}
Of course....that's without comments :)
  #3 (permalink)  
Old June 28th, 2003, 05:48 PM
Registered User
 
Join Date: Jun 2003
Location: Carlsbad, CA, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply...
After moving on I decided to go back and try it again...
voila.. it worked.. You're right, I had missed few things...
Now I back on the ball...

Thanks again:)

Odie
Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ivor Horton's Beginning C++ Firedrill C++ Programming 18 December 2nd, 2008 06:32 PM
Answers for Ivor Horton's Beginning C++ 7stud All Other Wrox Books 4 December 15th, 2006 10:59 AM
Where"Ivor Horton's Beginning Java 2" execiseAnswe yuanhuajie BOOK: Beginning Java 2, JDK 5 Edition 2 June 11th, 2006 10:34 PM
Where"Ivor Horton's Beginning Java 2" execiseAnswe yuanhuajie Java Basics 0 June 11th, 2006 09:47 PM
Errata for Ivor Horton's Beginning C++? 7stud C++ Programming 3 August 28th, 2003 05:51 PM



All times are GMT -4. The time now is 12:22 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.