Welcome to Dream.In.Code
Become a C++ Expert!

Join 150,017 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,471 people online right now. Registration is fast and FREE... Join Now!




String Manipulation

 
Reply to this topicStart new topic

String Manipulation

okyup
13 Nov, 2006 - 10:57 AM
Post #1

D.I.C Head
Group Icon

Joined: 6 Nov, 2006
Posts: 207


Dream Kudos: 175
My Contributions
Trying to figure out how this doesnt work for like 45 minutes and i think i must doing something stupid. sleepy.gif

If you see plz point out. BTW its supposed to take 2 special strings and output them in 2 columns. huh.gif

CODE
string sortOutput(string output1, string output2)
{
    string result="";
    int h1=output1.length();
    int h2=output2.length();
    int pos1=output1.find('\n');
    int pos2=output2.find('\n');
    int pos3,pos4;
    while ((pos1>=0 && pos1<h1) && (pos2>=0 && pos2<h2))
    {
        pos3=output1.find('\n',pos1);
        if (pos3>=0 && pos3<h1)
        {
            result=result+output1.substr(pos1+2,pos3-2);
        }
        else
        {
            result=result+"\t";
        }
        pos1=pos3;
        
        pos4=output2.find('\n',pos2);
        if (pos4>-1 && pos4<h2)
        {
            result=result+output2.substr(pos2+2,pos4-2);
        }
        else
        {
            result=result+"\n";
        }
        pos2=pos4;
    }
    return result;
}

User is offlineProfile CardPM
+Quote Post

Amadeus
RE: String Manipulation
13 Nov, 2006 - 10:58 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,355



Thanked: 51 times
Dream Kudos: 25
My Contributions
Title edited for relevance.

Can you please describe the problem you are encountering, or post any errors that are being generated?
User is offlineProfile CardPM
+Quote Post

okyup
RE: String Manipulation
13 Nov, 2006 - 11:02 AM
Post #3

D.I.C Head
Group Icon

Joined: 6 Nov, 2006
Posts: 207


Dream Kudos: 175
My Contributions
Compiles but hangs when it reaches that function.

I think theres something messed up in my loop lol. :| Also tried to add debugging info and it doesnt display it. sad.gif
User is offlineProfile CardPM
+Quote Post

okyup
RE: String Manipulation
13 Nov, 2006 - 11:09 AM
Post #4

D.I.C Head
Group Icon

Joined: 6 Nov, 2006
Posts: 207


Dream Kudos: 175
My Contributions
Oh man i knew i was dumb. You can delete this if you like. crazy.gif

have to add +1 to find position i guess. blink.gif (illogical lol)
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 09:06PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month