473,383 Members | 1,862 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,383 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 3235
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 ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.