C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 18th, 2003, 06:12 PM
henslecd henslecd is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 15 henslecd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
breaking up a string

What is the proper way to break up a string and get what you need out of it?

This is what I have...

I read a string in, say "blue 4 5".

What I want to be able to do is compare the first part of the string, blue, to blue. If they are equal, I need to read the last part, 4 5, in as a date. There is a lot more to this, but I am curious as to how to break up the string.

What I think I need to do is read the string in, blue 4 5.

Use a for loop to read the first 5 letters. Append those first 5 letters to a string, and compare that string to "blue ".

If they are equal, I use a for loop starting with index 6 and ending with 8, and read in the date. I then send that date to my queue.

Am I doing this right? Is there an easier way to break up the string?

Thanks for the help.

Reply With Quote
  #2  
Old June 18th, 2003, 08:54 PM
Jason Doucette's Avatar
Jason Doucette Jason Doucette is offline
jasondoucette.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 378 Jason Doucette User rank is Private First Class (20 - 50 Reputation Level)Jason Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 6
There are several functions that may be useful to you...

strtok() - Find the next token in a string.

You could use that to find the spaces in the string to separate it into individual substrings.

strspn() - Find the first substring.

You could use this to find a substring in another string. It all depends on what you are trying to do. It seems to me that your specific case could allow you to write your own string searching function, like you said, which would be fastest.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > breaking up a string


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT