473,230 Members | 1,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

Splitting function

Hi i m new at C and trying to write a parser and a string class.
Basicly program will read data from file and splits it into lines then
lines to words. i used strtok function for splitting data to lines it
worked quite well but srttok isnot working for multiple blank or
commas. Can strtok do this kind of splitting if it cant what should i
use .

Unal

Jun 8 '07 #1
2 3221
shadow_ wrote:
Hi i m new at C and trying to write a parser and a string class.
Basicly program will read data from file and splits it into lines then
lines to words. i used strtok function for splitting data to lines it
worked quite well but srttok isnot working for multiple blank or
commas. Can strtok do this kind of splitting if it cant what should i
use .
It depends on what you mean by "this kind" of splitting.

One feature of strtok() is that any unbroken sequence of
delimiter characters is combined into a single delimiter.
For example, if the comma is the only delimiter character
the string "a,,b" will be divided into two tokens "a" and
"b", not into three tokens "a", "", and "b". Furthermore,
if comma and semicolon are delimiter characters, then the
string ";a,;,b;" divides into "a" and "b". strtok() returns
no information about the identity or quantity of delimiting
characters it finds, but concentrates entirely on the tokens
that they separate.

Another feature of strtok() is that it "remembers" the
string it is working on: when you pass NULL as the first
argument, it tells strtok() to proceed with the tail end
of the string it examined on the preceding call. This has
an important implication: strtok() can only process one
string at a time, because it can remember only one string --
if it were somehow able to remember twelve strings, how would
it know which one a NULL referred to? So if you have a loop
that divides a buffer into lines with strtok(...,"\n") and
you also have an inner loop that breaks each line into words
with something like strtok(...," \t"), it won't work: as soon
as the inner loop starts work on a line, strtok() will "forget"
its position in the outer loop.

I'm not sure what to suggest as an alternative or as a
remedy, because you haven't explained "this kind" of splitting
precisely enough: you say that strtok() "isnot working," but
you haven't described how it fails to meet your needs. Perhaps
you should use fgets() to read a line at a time (making the
line-splitting strtok() unnecessary) and then use strtok() to
divide each line into words. If you need more information about
the number and kind of delimiters, though, strtok() is not the
answer.

--
Eric Sosman
es*****@acm-dot-org.invalid
Jun 8 '07 #2
Eric Sosman wrote:
>
.... snip ...
>
I'm not sure what to suggest as an alternative or as a remedy,
because you haven't explained "this kind" of splitting precisely
enough: you say that strtok() "isnot working," but you haven't
described how it fails to meet your needs. Perhaps you should
use fgets() to read a line at a time (making the line-splitting
strtok() unnecessary) and then use strtok() to divide each line
into words. If you need more information about the number and
kind of delimiters, though, strtok() is not the answer.
The OP can go back a few days and search for my publication of
toksplit (since renamed to tknsplit for standardization reasons).
This might fill his requirements.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jun 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: robsom | last post by:
Hi, I have a problem with a small python program I'm trying to write and I hope somebody may help me. I'm working on tables of this kind: CGA 1988 06 21 13 48 G500-050 D 509.62 J.. R1 1993 01...
3
by: Rakesh | last post by:
Hi, I was 'googling' to look out for some ways of optimizing the code and came across this term - 'hot / cold splitting'. In short, the discussion is about splitting heavily accessed ( hot )...
11
by: Steve Darby | last post by:
Can anyone help with this problem. I am attempting to dynamically draw a graph using data from a cookie. I have written the script to actually draw the graph, for which I hav created two arrays...
6
by: nwheavyw8 | last post by:
I am currently trying to write a simple PHP script that will split an uploading file up into 500kb "chunks", then read and concatenate them back together when accessed for download. I can't seem...
5
by: fatted | last post by:
I'm trying to write a function which splits a string (possibly multiple times) on a particular character and returns the strings which has been split. What I have below is kind of (oh dear!)...
2
by: Trint Smith | last post by:
Ok, My program has been formating .txt files for input into sql server and ran into a problem...the .txt is an export from an accounting package and is only supposed to contain comas (,) between...
3
by: tac-tics | last post by:
I know about os.path.split(), but Is there any standard function for "fully" splitting a file's pathname? A function that is the opposite of the os.path.join() function? For example: In the...
4
by: Steven D'Aprano | last post by:
I'm trying to split a URL into components. For example: URL = 'http://steve:secret@www.domain.com.au:82/dir" + \ 'ectory/file.html;params?query#fragment' (joining the strings above with plus...
37
by: xyz | last post by:
I have a string 16:23:18.659343 131.188.37.230.22 131.188.37.59.1398 tcp 168 for example lets say for the above string 16:23:18.659343 -- time 131.188.37.230 -- srcaddress 22 ...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.