Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
opposite of strchr()
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  21 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
sinbad  
View profile  
 More options Oct 30 2012, 12:23 am
Newsgroups: comp.unix.programmer
From: sinbad <sinbad.sin...@gmail.com>
Date: Mon, 29 Oct 2012 21:23:20 -0700 (PDT)
Local: Tues, Oct 30 2012 12:23 am
Subject: opposite of strchr()
is there an equivalent lib api for opposite of strchr().
i referred the manual, i couldn't find one.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Barry Margolin  
View profile  
 More options Oct 30 2012, 1:26 am
Newsgroups: comp.unix.programmer
From: Barry Margolin <bar...@alum.mit.edu>
Date: Tue, 30 Oct 2012 01:26:10 -0400
Local: Tues, Oct 30 2012 1:26 am
Subject: Re: opposite of strchr()
In article <94e58990-7dba-406b-8845-71123b4caf07@googlegroups.com>,

 sinbad <sinbad.sin...@gmail.com> wrote:
> is there an equivalent lib api for opposite of strchr().
> i referred the manual, i couldn't find one.

What's the opposite of strchr()? I assume you don't mean strrchr(). Do
you mean you want to find the first character that ISN'T a specific
character? Maybe it's overkill, but a regexp library can do this easily
with the RE [^c], where c is the character.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jérémie Courrèges-Anglas  
View profile  
 More options Oct 30 2012, 3:08 am
Newsgroups: comp.unix.programmer
From: jca+n...@wxcvbn.morg (Jérémie Courrèges-Anglas)
Date: Tue, 30 Oct 2012 07:54:15 +0100
Local: Tues, Oct 30 2012 2:54 am
Subject: Re: opposite of strchr()

Barry Margolin <bar...@alum.mit.edu> writes:
> In article <94e58990-7dba-406b-8845-71123b4caf07@googlegroups.com>,
>  sinbad <sinbad.sin...@gmail.com> wrote:

>> is there an equivalent lib api for opposite of strchr().
>> i referred the manual, i couldn't find one.

> What's the opposite of strchr()? I assume you don't mean strrchr().

Indeed, too briefly specified.

> Do you mean you want to find the first character that ISN'T a specific
> character? Maybe it's overkill, but a regexp library can do this easily
> with the RE [^c], where c is the character.

In that case, take a look at strcspn().

--
Jérémie Courrèges-Anglas
GPG fingerprint : 61DB D9A0 00A4 67CF 2A90 8961 6191 8FBF 06A1 1494


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Keith Thompson  
View profile  
 More options Oct 31 2012, 6:51 pm
Newsgroups: comp.unix.programmer
From: Keith Thompson <ks...@mib.org>
Date: Wed, 31 Oct 2012 15:51:40 -0700
Local: Wed, Oct 31 2012 6:51 pm
Subject: Re: opposite of strchr()

sinbad <sinbad.sin...@gmail.com> writes:
> is there an equivalent lib api for opposite of strchr().
> i referred the manual, i couldn't find one.

strchr() finds the first occurrence of a character in a string.

I suppose the "opposite() of strchr()" would be a function that
*doesn't* find the first occurrence of a character in a string.

sqrt() is a good example of that.  If sqrt() doesn't meet your
requirements, please state them more clearly.

--
Keith Thompson (The_Other_Keith) ks...@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott Lurndal  
View profile  
 More options Nov 1 2012, 10:09 am
Newsgroups: comp.unix.programmer
From: sc...@slp53.sl.home (Scott Lurndal)
Date: Thu, 01 Nov 2012 14:09:28 GMT
Local: Thurs, Nov 1 2012 10:09 am
Subject: Re: opposite of strchr()

Keith Thompson <ks...@mib.org> writes:
>sinbad <sinbad.sin...@gmail.com> writes:
>> is there an equivalent lib api for opposite of strchr().
>> i referred the manual, i couldn't find one.

>strchr() finds the first occurrence of a character in a string.

>I suppose the "opposite() of strchr()" would be a function that
>*doesn't* find the first occurrence of a character in a string.

Or it could be a function that finds the _last_ occurance of a character
in a string, e.g. strrchr().   However, since that is described on the
same man page in most systems, it's probably not what the OP intended.

scott


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sinbad  
View profile  
 More options Nov 1 2012, 11:09 am
Newsgroups: comp.unix.programmer
From: sinbad <sinbad.sin...@gmail.com>
Date: Thu, 1 Nov 2012 08:09:00 -0700 (PDT)
Subject: Re: opposite of strchr()

strchr() finds the first occurrence of a certain character 'c'.
By opposite of strchr(), i mean, find the first character that
isn't 'c'. I apologize for the lack of clarity. strcspn() seems
to work for the need.

-sinbad


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bjarni Juliusson  
View profile  
 More options Nov 1 2012, 11:31 am
Newsgroups: comp.unix.programmer
From: Bjarni Juliusson <bja...@update.uu.se>
Date: Thu, 01 Nov 2012 16:31:01 +0100
Local: Thurs, Nov 1 2012 11:31 am
Subject: Re: opposite of strchr()
On 11/01/2012 03:09 PM, Scott Lurndal wrote:

> Keith Thompson<ks...@mib.org>  writes:

>>strchr() finds the first occurrence of a character in a string.

>>I suppose the "opposite() of strchr()" would be a function that
>>*doesn't* find the first occurrence of a character in a string.

> Or it could be a function that finds the _last_ occurance of a character
> in a string, e.g. strrchr().   However, since that is described on the
> same man page in most systems, it's probably not what the OP intended.

Could be a function that takes a character and a string and loses the
character somewhere in the string.

Bjarni
--

                        INFORMATION WANTS TO BE FREE


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan Wagner  
View profile  
 More options Oct 31 2012, 9:14 pm
Newsgroups: comp.unix.programmer
From: Nathan Wagner <n...@hydaspes.if.org>
Date: 01 Nov 2012 01:14:15 +0000
Local: Wed, Oct 31 2012 9:14 pm
Subject: Re: opposite of strchr()
On 2012-10-31, Keith Thompson <ks...@mib.org> wrote:

> sinbad <sinbad.sin...@gmail.com> writes:
>> is there an equivalent lib api for opposite of strchr().
>> i referred the manual, i couldn't find one.

> strchr() finds the first occurrence of a character in a string.

> I suppose the "opposite() of strchr()" would be a function that
> *doesn't* find the first occurrence of a character in a string.

Not necessarily.  "Opposite" here doesn't have to refer to
the finding.  It could be the opposite of first, occurance, character,
or string.

So, it could find the last occurance, the first non-occurance,
the first non-character in a string (impossible I think, due
to the definition of a string), or the first character in a non-string
(also impossible I think, strings are the only objects that have
multiple characters, unless you want to somehow count byte
arrays).

IIRC, C has functions for the first two "opposites".

> sqrt() is a good example of that.

While I suppose that sqrt() doesn't do that, it isn't really
in the category of things that might.  Which I imagine was
your point.

> If sqrt() doesn't meet your requirements, please state them more
> clearly.

Indeed.  Though accurately stating requirements is sadly a rare
skill.

--
nw


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Barry Schwarz  
View profile  
 More options Nov 1 2012, 3:13 pm
Newsgroups: comp.unix.programmer
From: Barry Schwarz <schwa...@dqel.com>
Date: Thu, 01 Nov 2012 12:13:28 -0700
Local: Thurs, Nov 1 2012 3:13 pm
Subject: Re: opposite of strchr()
On Thu, 1 Nov 2012 08:09:00 -0700 (PDT), sinbad

Then you still haven't described what you really want.

    strcspn("abcd", "a");
and
    strcspn("aacd", "a");
both return 0.  How does that help you find the 'b' in the first case
and the 'c' in the second?

--
Remove del for email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Keith Thompson  
View profile  
 More options Nov 1 2012, 6:56 pm
Newsgroups: comp.unix.programmer
From: Keith Thompson <ks...@mib.org>
Date: Thu, 01 Nov 2012 15:56:35 -0700
Local: Thurs, Nov 1 2012 6:56 pm
Subject: Re: opposite of strchr()

Nathan Wagner <n...@hydaspes.if.org> writes:
> On 2012-10-31, Keith Thompson <ks...@mib.org> wrote:
>> sinbad <sinbad.sin...@gmail.com> writes:
>>> is there an equivalent lib api for opposite of strchr().
>>> i referred the manual, i couldn't find one.

>> strchr() finds the first occurrence of a character in a string.

>> I suppose the "opposite() of strchr()" would be a function that
>> *doesn't* find the first occurrence of a character in a string.

> Not necessarily.  "Opposite" here doesn't have to refer to
> the finding.  It could be the opposite of first, occurance, character,
> or string.

Of course not *necessarily*.

> So, it could find the last occurance, the first non-occurance,
> the first non-character in a string (impossible I think, due
> to the definition of a string), or the first character in a non-string
> (also impossible I think, strings are the only objects that have
> multiple characters, unless you want to somehow count byte
> arrays).

And it's pointless to speculate until the OP clarifies his
requirements -- which he has (possibly after you posted this;
I didn't bother checking timestamps).

>> sqrt() is a good example of that.

> While I suppose that sqrt() doesn't do that, it isn't really
> in the category of things that might.  Which I imagine was
> your point.

That was exactly my point.

[...]

--
Keith Thompson (The_Other_Keith) ks...@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Keith Thompson  
View profile  
 More options Nov 1 2012, 6:59 pm
Newsgroups: comp.unix.programmer
From: Keith Thompson <ks...@mib.org>
Date: Thu, 01 Nov 2012 15:59:21 -0700
Local: Thurs, Nov 1 2012 6:59 pm
Subject: Re: opposite of strchr()

There likely isn't a predefined function that does what the OP wants,
but it would be nearly trivial to write one.

--
Keith Thompson (The_Other_Keith) ks...@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Barry Schwarz  
View profile  
 More options Nov 1 2012, 7:20 pm
Newsgroups: comp.unix.programmer
From: Barry Schwarz <schwa...@dqel.com>
Date: Thu, 01 Nov 2012 16:20:37 -0700
Local: Thurs, Nov 1 2012 7:20 pm
Subject: Re: opposite of strchr()
On Thu, 01 Nov 2012 15:59:21 -0700, Keith Thompson <ks...@mib.org>
wrote:

>Barry Schwarz <schwa...@dqel.com> writes:
>> On Thu, 1 Nov 2012 08:09:00 -0700 (PDT), sinbad
>> <sinbad.sin...@gmail.com> wrote:

snip

>>>strchr() finds the first occurrence of a certain character 'c'.
>>>By opposite of strchr(), i mean, find the first character that
>>>isn't 'c'. I apologize for the lack of clarity. strcspn() seems
>>>to work for the need.

>> Then you still haven't described what you really want.

>>     strcspn("abcd", "a");
>> and
>>     strcspn("aacd", "a");
>> both return 0.  How does that help you find the 'b' in the first case
>> and the 'c' in the second?

>There likely isn't a predefined function that does what the OP wants,
>but it would be nearly trivial to write one.

Yes, but we are still left to wonder how the OP can claim that strcspn
satisfies his stated requirement.  Either he has not stated the
requirement correctly or has not performed even the most rudimentary
testing.

--
Remove del for email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sinbad  
View profile  
 More options Nov 2 2012, 1:35 am
Newsgroups: comp.unix.programmer
From: sinbad <sinbad.sin...@gmail.com>
Date: Thu, 1 Nov 2012 22:35:18 -0700 (PDT)
Local: Fri, Nov 2 2012 1:35 am
Subject: Re: opposite of strchr()

On Friday, November 2, 2012 4:50:52 AM UTC+5:30, Barry Schwarz wrote:
> On Thu, 01 Nov 2012 15:59:21 -0700, Keith Thompson <ks...@mib.org>

> Yes, but we are still left to wonder how the OP can claim that strcspn

> satisfies his stated requirement.  Either he has not stated the

> requirement correctly or has not performed even the most rudimentary

> testing.

i needed the opposite of strchr() in the following situation.
i need to process a set of commands entered by the user,
the commands might look like like "add node list", "add node queue"
"delete node list". I need to fetch each entry and take
appropriate actions, for example if the cmd is "add node list"
after fetchnig the first entry "add" i know tha t it's add function.
now i need to fetch the second entry which would be "node" but my
cmd pointer is pointing past the "d" in "add". I need to move beyond
all the spaces between "add" and "node" to reach the entry "node",
since the cmd is entered by the user there can be any number of
spaces between "add" and "node". i needed an api which will skip
all the spaces and get me to "node" if i pass the string "     node".
strcspn() seems to work for me, if used like this.

    strcspn(cmd, "abcdefghijklmnopqrstuvwxyz"));

    where cmd is  "     node list"

i wrote my own function before i learnt about strcspn(),
but i prefer to use library routines if available.

-sinbad


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Barry Schwarz  
View profile  
 More options Nov 2 2012, 2:32 am
Newsgroups: comp.unix.programmer
From: Barry Schwarz <schwa...@dqel.com>
Date: Thu, 01 Nov 2012 23:32:37 -0700
Local: Fri, Nov 2 2012 2:32 am
Subject: Re: opposite of strchr()
On Thu, 1 Nov 2012 22:35:18 -0700 (PDT), sinbad

It is good you were able to solve your problem.  

The fact that it is a significantly different problem than the one in
your original post might explain why none of us thought to recommend
strcspn to you in the first place.

You might want to consider using strpbrk instead of strcspn to get
directly to the text you want.  And strtok would do even more of the
work for you but it is not thread safe.

--
Remove del for email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark  
View profile  
 More options Nov 2 2012, 5:15 am
Newsgroups: comp.unix.programmer
From: Mark <i...@dontgetlotsofspamanymore.invalid>
Date: Fri, 02 Nov 2012 09:09:27 +0000
Local: Fri, Nov 2 2012 5:09 am
Subject: Re: opposite of strchr()
On Mon, 29 Oct 2012 21:23:20 -0700 (PDT), sinbad

<sinbad.sin...@gmail.com> wrote:
>is there an equivalent lib api for opposite of strchr().
>i referred the manual, i couldn't find one.

!strchr()
--
(\__/)  M.
(='.'=) If a man stands in a forest and no woman is around
(")_(") is he still wrong?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Keith Thompson  
View profile  
 More options Nov 5 2012, 2:22 pm
Newsgroups: comp.unix.programmer
From: Keith Thompson <ks...@mib.org>
Date: Mon, 05 Nov 2012 11:22:46 -0800
Local: Mon, Nov 5 2012 2:22 pm
Subject: Re: opposite of strchr()
sinbad <sinbad.sin...@gmail.com> writes:

[...]
> i needed the opposite of strchr() in the following situation.

[snip]

A suggestion: Stop using the phrase "opposite of strchr()", and
instead just state what you need the function to do.  You'll avoid
a lot of confusion.

--
Keith Thompson (The_Other_Keith) ks...@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gordon Burditt  
View profile  
 More options Nov 8 2012, 7:27 pm
Newsgroups: comp.unix.programmer
From: gordonb.eo...@burditt.org (Gordon Burditt)
Date: Thu, 08 Nov 2012 18:27:19 -0600
Local: Thurs, Nov 8 2012 7:27 pm
Subject: Re: opposite of strchr()

> A suggestion: Stop using the phrase "opposite of strchr()", and
> instead just state what you need the function to do.  You'll avoid
> a lot of confusion.

The opposite of strchr() clearly means a function that takes a character
as an argument and returns *all* strings containing that character (with
the minimum search space being the local filesystem and anything called
a "cloud", at least including any storage owned by Google or Amazon).

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Keith Thompson  
View profile  
 More options Nov 9 2012, 3:42 pm
Newsgroups: comp.unix.programmer
From: Keith Thompson <ks...@mib.org>
Date: Fri, 09 Nov 2012 12:42:58 -0800
Local: Fri, Nov 9 2012 3:42 pm
Subject: Re: opposite of strchr()

gordonb.eo...@burditt.org (Gordon Burditt) writes:
> Keith Thompson <ks...@mib.org> writes: [attribution line added]
>> A suggestion: Stop using the phrase "opposite of strchr()", and
>> instead just state what you need the function to do.  You'll avoid
>> a lot of confusion.

> The opposite of strchr() clearly means a function that takes a character
> as an argument and returns *all* strings containing that character (with
> the minimum search space being the local filesystem and anything called
> a "cloud", at least including any storage owned by Google or Amazon).

Gordon, I've told you before that you do not have my permission
to quote anything I write to Usenet without attribution.  This has
not changed, and it applies to all newsgroups.

I have no idea why you don't just leave the attribution line
in place.  (I know your stated rationale, but it makes no sense).
If you insist on inconveniencing yourself, go ahead.  But if you
refuse to give credit where it's due, don't quote me.

Feel free to e-mail me if you want to discuss this privately.

--
Keith Thompson (The_Other_Keith) ks...@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nicolas George  
View profile  
 More options Nov 9 2012, 6:56 pm
Newsgroups: comp.unix.programmer
From: Nicolas George <nicolas$geo...@salle-s.org>
Date: 09 Nov 2012 23:56:53 GMT
Local: Fri, Nov 9 2012 6:56 pm
Subject: Re: opposite of strchr()
Keith Thompson , dans le message <lnobj6jynh....@nuthaus.mib.org>, a
  crit :

> Gordon, I've told you before that you do not have my permission
> to quote anything I write to Usenet without attribution.

Technically, there is an attribution in his message: the References header.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Keith Thompson  
View profile  
 More options Nov 9 2012, 10:35 pm
Newsgroups: comp.unix.programmer
From: Keith Thompson <ks...@mib.org>
Date: Fri, 09 Nov 2012 19:35:53 -0800
Local: Fri, Nov 9 2012 10:35 pm
Subject: Re: opposite of strchr()

Nicolas George <nicolas$geo...@salle-s.org> writes:
> Keith Thompson , dans le message <lnobj6jynh....@nuthaus.mib.org>, a
>  écrit :
>> Gordon, I've told you before that you do not have my permission
>> to quote anything I write to Usenet without attribution.

> Technically, there is an attribution in his message: the References
> header.

I wouldn't call that an attribution.  The purpose of an attribution line
is to indicate to the reader who wrote what, and to make the discussion
easier to follow.

--
Keith Thompson (The_Other_Keith) ks...@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
luser.droog  
View profile  
 More options Nov 19 2012, 1:46 am
Newsgroups: comp.unix.programmer
From: "luser.droog" <luser.dr...@gmail.com>
Date: Mon, 19 Nov 2012 00:46:27 -0600
Local: Mon, Nov 19 2012 1:46 am
Subject: Re: opposite of strchr()

Sounds to me like you need to use strtok() to chop the string into words;
and strcmp() to find out what the word is. Many english words begin
with 'a' followed by not-'a'.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »