Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How to extract a string starting with 'abc' & ending with 'xyz' ?

Reply
Thread Tools

How to extract a string starting with 'abc' & ending with 'xyz' ?

 
 
Barry Schwarz
Guest
Posts: n/a
 
      06-03-2007
On Sun, 03 Jun 2007 03:49:06 -0700, Umesh
<(E-Mail Removed)> wrote:

>How to modify it so that it stops searcing for strings containing
>'uvw' ?


snip 150 lines

While not wishing to respond to the troll, I think it appropriate to
warn new students of the language not to use his code as an example of
working code or good programming practice or even usenet etiquette.


Remove del for email
 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      06-03-2007
In article <(E-Mail Removed). com>,
Umesh <(E-Mail Removed)> wrote:

>> // find a string stating with abc and ending with xyz WORKING


>> abc = strstr(buf, "abc");
>> if (abc != NULL)
>> {
>> xyz = strstr(abc + 3, "xyz");
>> if (xyz != NULL)
>> fprintf (outfp,"%.*s\n",(int)(xyz + 3 - abc), abc);
>> }


That doesn't find strings beginning with abc and ending with xyz:
that finds strings beginning with abc and having xyz in them anywhere,
and prints out the portion from the abc to the xyz.

If the goal is to extract from abc up to the first xyz, then the
phrase to use is "find substrings starting with abc and ending with xyz".
When you say that you want to "find strings [...] ending with xyz", then
the implication is that you are examining a complete string and the
last thing in that string is xyz.
--
If you lie to the compiler, it will get its revenge. -- Henry Spencer
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
3 ESSENTIAL TOOLS FOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLSFOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLS FOR STARTING ANDMAINTAINING... Oanh Bui C++ 0 04-27-2009 12:51 PM
3 ESSENTIAL TOOLS FOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLSFOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLS FOR STARTING ANDMAINTAINING... Oanh Bui C Programming 0 04-27-2009 12:51 PM
3 ESSENTIAL TOOLS FOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLSFOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLS FOR STARTING ANDMAINTAINING... Oanh Bui Python 0 04-27-2009 12:46 PM
Delete starting and ending lines of a file Srinivasa T.N. Perl 7 12-01-2003 06:52 AM



Advertisments