Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-11-2003, 02:57 PM
|
#1
|
LQ Newbie
Registered: Aug 2003
Location: Sweden
Posts: 4
Rep:
|
Read until a certain character?
Is there some easy way to read from a file descriptor until i run into a certain character?
For example if I read the following:
Hello&Bye&
I would want it to stop reading at the & and put 'Hello' or possibly 'Hello&' in the buffer, and at the second run it would read 'Bye.'
|
|
|
08-11-2003, 03:04 PM
|
#2
|
Member
Registered: Jul 2003
Location: DC
Distribution: mandrake 9.1
Posts: 415
Rep:
|
what do you mean by second run?
like you want the program to end and when you start it up again it'll do the second word?
|
|
|
08-11-2003, 03:49 PM
|
#3
|
Member
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288
Rep:
|
What programming language?
In most general terms you either want to read character by character (checking for the &, etc) or read one line at a time and split it afterwards. If it's C/C++ or Perl i might be able to help you.
Cheers,
|
|
|
08-11-2003, 04:05 PM
|
#4
|
Member
Registered: Jun 2001
Location: Recycle Bin
Distribution: Linux & Everything else on VirtualBox
Posts: 144
Rep:
|
echo "Hello&Bye&"|sed -e's/&/ /g'
Hello Bye
echo "Hello&Bye&"|cut -d '&' --output-delimiter=" " -f 1,2
Hello Bye
|
|
|
08-11-2003, 04:52 PM
|
#5
|
Senior Member
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821
Rep: 
|
If you are using C you can read the entire string and tokenize it with strtok. If using C++ there is a string tokenizer in the std string class.
|
|
|
08-12-2003, 10:24 AM
|
#6
|
LQ Newbie
Registered: Aug 2003
Location: Sweden
Posts: 4
Original Poster
Rep:
|
I'm writing it in C, and strtok seems to be just what I'm looking for, thank you very much.
_______
andreas
|
|
|
All times are GMT -5. The time now is 09:17 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|