473,802 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

strsep() function problem, please help

Hi everyone,

I'm trying to get this program compiled under Solaris. Unfortunately I
have little experience with C.

Solaris doesn't use the function strsep() anymore:
char *strsep(char **stringp, const char *delim);

DESCRIPTION
The strsep() function returns the next token from the
string stringp which is delimited by delim. The token is
terminated with a `\0' character and stringp is updated to
point past the token.

RETURN VALUE
The strsep() function returns a pointer to the token, or
NULL if delim is not found in stringp.

I need to use a function that Solaris knows about. Tried to simply
substitute strsep() with strtok() which didn't work. The code which I
need to port is:

while (fgets(buf, sizeof(buf), desc) != NULL) {
w = buf;
if ((p = strsep(&w, " \t")) == NULL)
continue;
..
..
..

Any help would be greatly appreciated since google and everyone I know
couldn't help.

-Dan

Nov 14 '05 #1
9 4009
Try this code.

while (fgets(buf, sizeof(buf), desc) != NULL) {
w = buf;
strtok(w, "\t");
if ((p = strtok(NULL, " \t")) == NULL)
continue;

<da****@best.de > wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi everyone,

I'm trying to get this program compiled under Solaris. Unfortunately I
have little experience with C.

Solaris doesn't use the function strsep() anymore:
char *strsep(char **stringp, const char *delim);

DESCRIPTION
The strsep() function returns the next token from the
string stringp which is delimited by delim. The token is
terminated with a `\0' character and stringp is updated to
point past the token.

RETURN VALUE
The strsep() function returns a pointer to the token, or
NULL if delim is not found in stringp.

I need to use a function that Solaris knows about. Tried to simply
substitute strsep() with strtok() which didn't work. The code which I
need to port is:

while (fgets(buf, sizeof(buf), desc) != NULL) {
w = buf;
if ((p = strsep(&w, " \t")) == NULL)
continue;
.
.
.

Any help would be greatly appreciated since google and everyone I know
couldn't help.

-Dan

Nov 14 '05 #2
Of course, strtok(w, "\t"); should be replaced with strtok(w, " \t"); in the
3rd line of my code.

"thilbong" <ty****@vt.ed u> wrote in message
news:d8******** **@solaris.cc.v t.edu...
Try this code.

while (fgets(buf, sizeof(buf), desc) != NULL) {
w = buf;
strtok(w, "\t");
if ((p = strtok(NULL, " \t")) == NULL)
continue;

<da****@best.de > wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi everyone,

I'm trying to get this program compiled under Solaris. Unfortunately I
have little experience with C.

Solaris doesn't use the function strsep() anymore:
char *strsep(char **stringp, const char *delim);

DESCRIPTION
The strsep() function returns the next token from the
string stringp which is delimited by delim. The token is
terminated with a `\0' character and stringp is updated to
point past the token.

RETURN VALUE
The strsep() function returns a pointer to the token, or
NULL if delim is not found in stringp.

I need to use a function that Solaris knows about. Tried to simply
substitute strsep() with strtok() which didn't work. The code which I
need to port is:

while (fgets(buf, sizeof(buf), desc) != NULL) {
w = buf;
if ((p = strsep(&w, " \t")) == NULL)
continue;
.
.
.

Any help would be greatly appreciated since google and everyone I know
couldn't help.

-Dan


Nov 14 '05 #3
"thilbong" <ty****@vt.ed u> wrote in message
news:d8******** **@solaris.cc.v t.edu...
Of course, strtok(w, "\t"); should be replaced with strtok(w, " \t"); in
the 3rd line of my code.
Of course, your solution isn't really a solution regardless of the 3rd line!
The strsep() function returns the next token from the
string stringp which is delimited by delim. The token is
terminated with a `\0' character and stringp is updated to
point past the token.


while(fgets(buf , sizeof buf, desc)) {
if((w = strcspn(buf, " \t")) == NULL)
continue;
*w++ = 0;
p = buf;
...
}

Untested, but it should work.
Regards,
Mark

"thilbong" <ty****@vt.ed u> wrote in message
news:d8******** **@solaris.cc.v t.edu...
Try this code.

while (fgets(buf, sizeof(buf), desc) != NULL) {
w = buf;
strtok(w, "\t");
if ((p = strtok(NULL, " \t")) == NULL)
continue;

<da****@best.de > wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi everyone,

I'm trying to get this program compiled under Solaris. Unfortunately I
have little experience with C.

Solaris doesn't use the function strsep() anymore:
char *strsep(char **stringp, const char *delim);

DESCRIPTION
The strsep() function returns the next token from the
string stringp which is delimited by delim. The token is
terminated with a `\0' character and stringp is updated to
point past the token.

RETURN VALUE
The strsep() function returns a pointer to the token, or
NULL if delim is not found in stringp.

I need to use a function that Solaris knows about. Tried to simply
substitute strsep() with strtok() which didn't work. The code which I
need to port is:

while (fgets(buf, sizeof(buf), desc) != NULL) {
w = buf;
if ((p = strsep(&w, " \t")) == NULL)
continue;
.
.
.

Any help would be greatly appreciated since google and everyone I know
couldn't help.

-Dan



Nov 14 '05 #4

"Mark" <so***@localbar .com> wrote in message
news:Bp******** ********@newsho g.newsread.com. ..
"thilbong" <ty****@vt.ed u> wrote in message
news:d8******** **@solaris.cc.v t.edu...
Of course, strtok(w, "\t"); should be replaced with strtok(w, " \t"); in
the 3rd line of my code.
Of course, your solution isn't really a solution regardless of the 3rd
line!

And neither is mine!
should be: strpbrk() not strcspn() !
*oops* maybe I should have tested it first!

while(fgets(buf , sizeof buf, desc)) {
if((w = strpbrk(buf, " \t")) == NULL)
continue;
*w++ = 0;
p = buf;
...
}

Still untested ;) But much better...
Mark
The strsep() function returns the next token from the
string stringp which is delimited by delim. The token is
terminated with a `\0' character and stringp is updated to
point past the token.


while(fgets(buf , sizeof buf, desc)) {
if((w = strcspn(buf, " \t")) == NULL)
continue;
*w++ = 0;
p = buf;
...
}

Untested, but it should work.
Regards,
Mark

"thilbong" <ty****@vt.ed u> wrote in message
news:d8******** **@solaris.cc.v t.edu...
Try this code.

while (fgets(buf, sizeof(buf), desc) != NULL) {
w = buf;
strtok(w, "\t");
if ((p = strtok(NULL, " \t")) == NULL)
continue;

<da****@best.de > wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi everyone,

I'm trying to get this program compiled under Solaris. Unfortunately I
have little experience with C.

Solaris doesn't use the function strsep() anymore:
char *strsep(char **stringp, const char *delim);

DESCRIPTION
The strsep() function returns the next token from the
string stringp which is delimited by delim. The token is
terminated with a `\0' character and stringp is updated to
point past the token.

RETURN VALUE
The strsep() function returns a pointer to the token, or
NULL if delim is not found in stringp.

I need to use a function that Solaris knows about. Tried to simply
substitute strsep() with strtok() which didn't work. The code which I
need to port is:

while (fgets(buf, sizeof(buf), desc) != NULL) {
w = buf;
if ((p = strsep(&w, " \t")) == NULL)
continue;
.
.
.

Any help would be greatly appreciated since google and everyone I know
couldn't help.

-Dan



Nov 14 '05 #5
On Tue, 14 Jun 2005 08:35:49 -0700, daniel wrote:
Hi everyone,

I'm trying to get this program compiled under Solaris. Unfortunately I
have little experience with C.

Solaris doesn't use the function strsep() anymore:
char *strsep(char **stringp, const char *delim);

DESCRIPTION
The strsep() function returns the next token from the
string stringp which is delimited by delim. The token is
terminated with a `\0' character and stringp is updated to
point past the token.

RETURN VALUE
The strsep() function returns a pointer to the token, or
NULL if delim is not found in stringp.

I need to use a function that Solaris knows about. Tried to simply
substitute strsep() with strtok() which didn't work. The code which I
need to port is:


strsep() isn't a standard C library function but common implementations
work differently to strtok(), which is the reason for it in the first
place. strtok() treats a sequence of delimeter characters as a single
separator field e.g. using \t delimiters field1\t\tfield 2 is 2 fields.
strsep() would produce 3 i.e. with a zero length middle field. If you need
this functionality then you can't use strtok().

A simple solution would be to grab source code for strsep() from the Web,
it is a small function and a Google search of strsep source gives lots
of matches.

Lawrence
Nov 14 '05 #6
da****@best.de wrote:

I'm trying to get this program compiled under Solaris.
Unfortunately I have little experience with C.

Solaris doesn't use the function strsep() anymore:

char *strsep(char **stringp, const char *delim);

DESCRIPTION
The strsep() function returns the next token from the
string stringp which is delimited by delim. The token is
terminated with a `\0' character and stringp is updated to
point past the token.

RETURN VALUE
The strsep() function returns a pointer to the token, or
NULL if delim is not found in stringp.

I need to use a function that Solaris knows about. Tried to
simply substitute strsep() with strtok() which didn't work. The
code which I need to port is:

while (fgets(buf, sizeof(buf), desc) != NULL) {
w = buf;
if ((p = strsep(&w, " \t")) == NULL)
continue;
.
.

Any help would be greatly appreciated since google and everyone
I know couldn't help.


It seems rather useless, since very few lines are going to use both
the space and a following tab as a token separator, which is what
you want according to your description of strsep. If that is the
logic you want look into strstr(), else look into strpbrk(), both
of which are standard functions.

I suspect what you really want is to find an occurrence of one or
more of those characters, after skipping leading occasions, and
that you don't want to use strtok because of it's re-entrancy
problems. You might want to simplify by making the delimiters any
whitespace, which will include \n and \f. So I would write a
routine to do this something like (untested):

/* This has the nuisance of strtok, it alters str content */
/* so it can't parse string constants, for example. However */
/* it doesn't have the reentrancy and threading problems */
char *sepstr(char* *str)
{
char *s = *str; /* scan off leading delims */
char *t; /* scan to next token */

while (isspace((unsig ned char)*s)) s++;
if (!*s) return NULL;
t = s;
while (t && !isspace(unsign ed char)*t) t++;
if (t) *t++ = '\0';
*str = t;
return s;
} /* untested */

I am not sure but that isspace is a C99 function; if so you may
have to build it out of the other is functions or first principles.

This may all be foolish because sscanf may also do the job for
you. However I rarely use the scanf family - it's too complicated
for me. Dan Pop would choose otherwise.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson

Nov 14 '05 #7
I verified that my solution worked well, at least as I intended to. :-)

"Mark" <so***@localbar .com> wrote in message
news:Bp******** ********@newsho g.newsread.com. ..
"thilbong" <ty****@vt.ed u> wrote in message
news:d8******** **@solaris.cc.v t.edu...
Of course, strtok(w, "\t"); should be replaced with strtok(w, " \t"); in
the 3rd line of my code.


Of course, your solution isn't really a solution regardless of the 3rd
line!
The strsep() function returns the next token from the
string stringp which is delimited by delim. The token is
terminated with a `\0' character and stringp is updated to
point past the token.


while(fgets(buf , sizeof buf, desc)) {
if((w = strcspn(buf, " \t")) == NULL)
continue;
*w++ = 0;
p = buf;
...
}

Untested, but it should work.
Regards,
Mark

"thilbong" <ty****@vt.ed u> wrote in message
news:d8******** **@solaris.cc.v t.edu...
Try this code.

while (fgets(buf, sizeof(buf), desc) != NULL) {
w = buf;
strtok(w, "\t");
if ((p = strtok(NULL, " \t")) == NULL)
continue;

<da****@best.de > wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi everyone,

I'm trying to get this program compiled under Solaris. Unfortunately I
have little experience with C.

Solaris doesn't use the function strsep() anymore:
char *strsep(char **stringp, const char *delim);

DESCRIPTION
The strsep() function returns the next token from the
string stringp which is delimited by delim. The token is
terminated with a `\0' character and stringp is updated to
point past the token.

RETURN VALUE
The strsep() function returns a pointer to the token, or
NULL if delim is not found in stringp.

I need to use a function that Solaris knows about. Tried to simply
substitute strsep() with strtok() which didn't work. The code which I
need to port is:

while (fgets(buf, sizeof(buf), desc) != NULL) {
w = buf;
if ((p = strsep(&w, " \t")) == NULL)
continue;
.
.
.

Any help would be greatly appreciated since google and everyone I know
couldn't help.

-Dan



Nov 14 '05 #8
Thanky you very much for helping me out here, I was almost despairing.

So thanks for all the replies, the solution worked out very well!

Bye

-Dan

Nov 14 '05 #9
da****@best.de wrote:

Thanky you very much for helping me out here, I was almost despairing.

So thanks for all the replies, the solution worked out very well!

Bye


Too late, but here's what I got anyway:

#include <string.h>

char *str_sep(char **s1, const char *s2)
{
char *const p1 = *s1;

if (p1 != NULL) {
*s1 = strpbrk(p1, s2);
if (*s1 != NULL) {
*(*s1)++ = '\0';
}
}
return p1;
}

--
pete
Nov 14 '05 #10

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

Similar topics

11
3764
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class (ClassB* b; b->func(); ) the base-class function is called instead of the new function in the derived class. All other similar functions (virtual in the base class and overwritten in the the derived class) work fine, it's just this one function. ...
2
1955
by: Chris Michael | last post by:
Hello everybody, Newbie here. I've been working on this for the last two days and I can't figure out where this problem is. I think it's something so obvious, but I can't see it! OK, firstly in a very simple page (please see www.intomobiles.com/test3.htm - it just displays the code that i use in an asp page) I call a function "processForm". The actual form is described in an asp page and is SSI linked to the page (for the full...
4
3398
by: mangi03 | last post by:
Hi, I came acrosss g++ compile errors whenever I make a function call by reference and found out from the test program that compiler is treating the function argument differently when another function call funcRet()is made which returns the expected argument type for the function call by reference funcByRef(class A&); The only way to get around this probelm is to first call the funcRet(), assign its value to a variable and pass that...
2
6489
by: daniel | last post by:
Hi everyone, I'm trying to get this program compiled under Solaris. I have actually no idea about programming, sorry to bother you. Unfortunately Solaris don't use the function strsep() anymore: char *strsep(char **stringp, const char *delim);
2
9804
by: Chuck Martin | last post by:
I am having a most frustrating problem that references, web searches, and other resources are no help so far in solving. Basically, I'm trying to design a pop-up window to be called with a funciton in a link. that function can have parameters for URL and window name passed to it. This works peachy in Firefox (1.0). With IE 6 (6.0.29) on two separate computers, I get an "onject expected" error. Going to the MS-based debugger just tells me...
5
1713
by: mk | last post by:
Greetings all - im new to this newsgroup so pls dont flame me :p I need some help! Please view the html below in a browser. Or goto this url -http://firebrain.co.uk/java-problem.htm (Assuming you have seen the rendered code) Basically I need the X buttons to change all the values of each textbox to zero either in the col or row depending on which button is clicked. Function summery: If you click on a X button on the right hand side of...
3
8635
by: drummond.ian | last post by:
Hello Everyone, This problem's been causing me a lot of trouble and I'm hoping somebody can help me out!! I have a dialog-based MFC application in visual studio 2003. I want to call a function called "OnPrintMsg" from my dialog class called "MyAppDlg.h". The function needs to be called from another class called "Client.cpp". The Client class (derived from the CSockets class) exists as described below.
9
2905
by: shror | last post by:
hi every body, i have a problem which is when i was checking my mail() form it work fine but the problem is that the form configuration is not set correctly, in details: the from var is not working and the from is set to be my host provider email is the sender, so they told me to configure the php.ini file and i dont know what is this file and how to configure it. thanks in advance
8
1661
by: cpptutor2000 | last post by:
Could some C guru please help me? I have a function that takes as an argument a pointer to an array of unsigned chars (basically a hex representation of a dotted decimal IP address). When I print out the received values in the receiving function, I get something completely different from what I passed in. The following are the relevant code snippets: In the calling function: unsigned char* TempAddrs = {"0xC0", "0xA8", "0x00", "0x63"};
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10536
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10304
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.