LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 08-11-2003, 02:57 PM   #1
AndreasA
LQ Newbie
 
Registered: Aug 2003
Location: Sweden
Posts: 4

Rep: Reputation: 0
Question 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.'
 
Old 08-11-2003, 03:04 PM   #2
sk8guitar
Member
 
Registered: Jul 2003
Location: DC
Distribution: mandrake 9.1
Posts: 415

Rep: Reputation: 30
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?
 
Old 08-11-2003, 03:49 PM   #3
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
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,
 
Old 08-11-2003, 04:05 PM   #4
slapNUT
Member
 
Registered: Jun 2001
Location: Recycle Bin
Distribution: Linux & Everything else on VirtualBox
Posts: 144

Rep: Reputation: 15
echo "Hello&Bye&"|sed -e's/&/ /g'
Hello Bye

echo "Hello&Bye&"|cut -d '&' --output-delimiter=" " -f 1,2
Hello Bye
 
Old 08-11-2003, 04:52 PM   #5
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
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.
 
Old 08-12-2003, 10:24 AM   #6
AndreasA
LQ Newbie
 
Registered: Aug 2003
Location: Sweden
Posts: 4

Original Poster
Rep: Reputation: 0
Smile

I'm writing it in C, and strtok seems to be just what I'm looking for, thank you very much.



_______
andreas
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mounted read-write Fat32 partition suddenly becomes read-only?? hohead Linux - General 8 04-05-2007 12:17 PM
g77 Fortran - run time error (fmt: read unexpected character) rajeshdorai Programming 1 08-16-2006 07:07 AM
mozzla problems-can not read files online, can not read attachments sarajevo Linux - Software 1 09-20-2005 06:58 PM
Example share in smb.conf doesn't work - read/write vs read only kleptophobiac Linux - Networking 0 09-01-2004 07:14 PM
kernel panic unable to mount root (yes ive read/read other posts) dmx9595 Linux - General 4 01-17-2004 05:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration