techPowerUp! Forums

Go Back   techPowerUp! Forums > Software > Programming & Webmastering

Reply
 
Thread Tools
Old Mar 19, 2011, 03:00 AM   #1
[I.R.A]_FBi
Eligible for custom title
 
[I.R.A]_FBi's Avatar
 
Join Date: May 2007
Location: c:\programs\kitteh.exe
Posts: 6,152 (2.80/day)
Thanks: 724
Thanked 556 Times in 461 Posts

System Specs

Strings and Linked lists in C++

Working on a basic text editor in c++ using linked lists

i have a method that that accesses a class method called add that accepts words froma stringt for example "the aflac duck" gets broken into three items by insert and and get added to a link list by insert. running on the assumption so far that each word has 1 space between it.

Code:
void insert(string w1)
{
     string w2="";
     char c1;
     
     string::iterator it;
     for (it=w1.begin(); it < w1.end(); it++)
     {
         c1 = *it;
         
         if( c1 == ' ')
         {
             list.add(w2);
             w2="";
         }
         else
         {
             w2 = w2 + c1;
         }
     }
}
why if for example i do

Code:
insert(st1);
where st1 is a string do i get "the" when i do a readback

as opposed to if i use

[code]insert("the aflac duck");

i do a readback and get the whole string ... (the aflac duck)


what am i doing wrong
__________________
Rig 1+1
Athlon XP 2200+, MSI KM2M Combo, ATI 9200SE 128 MB DDR, 2 X 512 MB DDR333, 250GB + 80 HDD?

“try intel cpu, amd is only good for going to nude sites” -firehawkxd
“go for the 5850 now and play games while the nvidiots wait for the ceo to show an actual working product” -W1zzard
“An MSI logo? This offends my retina. I await your apology.” -MRCL

www.autolounge.com.jm
[I.R.A]_FBi is offline  
Reply With Quote
Old Mar 20, 2011, 12:31 PM   #2
Zyon
200 Posts
 
Zyon's Avatar
 
Join Date: Mar 2011
Location: Australia
Posts: 246 (0.31/day)
Thanks: 6
Thanked 31 Times in 28 Posts

System Specs

You don't have to check every character yourself until it is a space, try using stringstream from C++'s standard library:

#include <sstream>

Create the stringstream object, initialise it with the input string, and then do a while loop as long as the stream has character (stringstream.good()) and perform a getline using ' ' (space) as delimiter, then add the string obtained from getline() to your linked list.

I can give you a sample completed code if you need it.

(Just to make it easier for you, getline() takes in input stream, string parameter to output line to, and optionally delimiter)
Zyon is offline  
Reply With Quote
The Following User Says Thank You to Zyon For This Useful Post:
Old Mar 20, 2011, 12:34 PM   #3
Kreij
Hardcore Monkey Moderator
 
Kreij's Avatar
 
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 12,131 (5.27/day)
Thanks: 591
Thanked 5,494 Times in 2,938 Posts

System Specs

How are you telling it to display the separated string?
Could you inadvertantly be just displaying at the first string in the list and they are actaully all there?

Did you get my PM about converting to c-string and tokenizing?
__________________

Cloud (noun, singular): A dynamic arrangement of multiple potential single points of failure, with a user at one end and their data at the other.


Get more tech news on a wide variety of topics at NextPowerUp
Kreij is online now  
Reply With Quote
The Following User Says Thank You to Kreij For This Useful Post:
Old Mar 20, 2011, 05:49 PM   #4
[I.R.A]_FBi
Eligible for custom title
 
[I.R.A]_FBi's Avatar
 
Join Date: May 2007
Location: c:\programs\kitteh.exe
Posts: 6,152 (2.80/day)
Thanks: 724
Thanked 556 Times in 461 Posts

System Specs

thx guys. i got ur pm kreij.

i tried tokenizing but to no avail
__________________
Rig 1+1
Athlon XP 2200+, MSI KM2M Combo, ATI 9200SE 128 MB DDR, 2 X 512 MB DDR333, 250GB + 80 HDD?

“try intel cpu, amd is only good for going to nude sites” -firehawkxd
“go for the 5850 now and play games while the nvidiots wait for the ceo to show an actual working product” -W1zzard
“An MSI logo? This offends my retina. I await your apology.” -MRCL

www.autolounge.com.jm
[I.R.A]_FBi is offline  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked or unlinked? ste2425 Overclocking & Cooling 10 May 13, 2010 01:28 PM
ASUS Lists AM3 CPU-supportive AM2 and AM2+ Motherboards btarunr News 52 Nov 16, 2008 07:39 AM
nvidia 8800gt sub id strings Rebo&Zooty NVIDIA 0 May 19, 2008 05:22 AM
Memory linked or unlinked? CarolinaKSU Motherboards & Memory 2 Mar 4, 2008 02:11 PM
AMD lists FX-60 and X2 5000+ live2game2003 News 2 Oct 26, 2005 01:56 AM


All times are GMT. The time now is 10:37 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
no new posts