Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C++: Comparing Substrings In An Array

Reply
Thread Tools

C++: Comparing Substrings In An Array

 
 
Ying Yang
Guest
Posts: n/a
 
      09-24-2003
Hi,

What do i use to solve the following problem:

Pseudocode:

if my array of char contains a substring that is equal to string X
{
increment counter;
}
else do not increment counter.


Regards
KLJ




 
Reply With Quote
 
 
 
 
Ying Yang
Guest
Posts: n/a
 
      09-24-2003


> Hi,
>
> What do i use to solve the following problem:
>
> Pseudocode:
>
> if my array of char contains a substring that is equal to string X
> {
> increment counter;
> }
> else do not increment counter.


I forgot to add that i would like to do it without using the string data
type if possible.


Regardsd
tyu


 
Reply With Quote
 
 
 
 
Attila Feher
Guest
Posts: n/a
 
      09-24-2003
Ying Yang wrote:
> Hi,
>
> What do i use to solve the following problem:
>
> Pseudocode:
>
> if my array of char contains a substring that is equal to string X
> {
> increment counter;
> }
> else do not increment counter.


if I use the strstr function to check if my array of char
contains a substring that is equal to string X
{
++counter;
}


--
Attila aka WW


 
Reply With Quote
 
Thomas Matthews
Guest
Posts: n/a
 
      09-24-2003
Ying Yang wrote:
>>Hi,
>>
>>What do i use to solve the following problem:
>>
>>Pseudocode:
>>
>>if my array of char contains a substring that is equal to string X
>>{
>> increment counter;
>>}
>>else do not increment counter.

>
>
> I forgot to add that i would like to do it without using the string data
> type if possible.
>
>
> Regardsd
> tyu
>
>


strstr.


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

 
Reply With Quote
 
Chris Dams
Guest
Posts: n/a
 
      09-24-2003
"Ying Yang" <(E-Mail Removed)> writes:

Hello,

>> Hi,
>>
>> What do i use to solve the following problem:
>>
>> Pseudocode:
>>
>> if my array of char contains a substring that is equal to string X
>> {
>> increment counter;
>> }
>> else do not increment counter.


>I forgot to add that i would like to do it without using the string data
>type if possible.


If the string in your array of char is null terminated, you can use

STRSTR(3) Linux Programmer's Manual STRSTR(3)



NAME
strstr - locate a substring

SYNOPSIS
#include <string.h>

char *strstr(const char *haystack, const char *needle);

DESCRIPTION
The strstr() function finds the first occurrence of the
substring needle in the string haystack. The terminating
`\0' characters are not compared.

RETURN VALUE
The strstr() function returns a pointer to the beginning
of the substring, or NULL if the substring is not found.

Bye,
Chris Dams
 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      09-24-2003
Ying Yang wrote:

> I forgot to add that i would like to do it without using the string data
> type if possible.



Why? In C++, you should strive to use std::string whenever possible,
unless there is an overriding reason not to do so. Please explain your
special circumstances. That will help us give an accurate answer.




Brian Rodenborn
 
Reply With Quote
 
A
Guest
Posts: n/a
 
      09-25-2003
> Ying Yang wrote:
>
> > I forgot to add that i would like to do it without using the string data
> > type if possible.

>
>
> Why? In C++, you should strive to use std::string whenever possible,
> unless there is an overriding reason not to do so. Please explain your
> special circumstances. That will help us give an accurate answer.
>
> Brian Rodenborn


I am learning C++ and since alot of code still contains reminants of C, it's
a good idea to learn how to use functions from the older c library before
moving on to the C++ library.

LKDjdfdfgdfgf


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.518 / Virus Database: 316 - Release Date: 11/09/2003


 
Reply With Quote
 
Gavin Deane
Guest
Posts: n/a
 
      09-25-2003
"A" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> > Ying Yang wrote:
> >
> > > I forgot to add that i would like to do it without using the string data
> > > type if possible.

> >
> >
> > Why? In C++, you should strive to use std::string whenever possible,
> > unless there is an overriding reason not to do so. Please explain your
> > special circumstances. That will help us give an accurate answer.
> >
> > Brian Rodenborn

>
> I am learning C++ and since alot of code still contains reminants of C, it's
> a good idea to learn how to use functions from the older c library before
> moving on to the C++ library.


"as well as", maybe, but not "before". As Brian said, you should be
using std::string in your own code unless you have a very good reason
not to (other peeple's avoidance of std::string is not a good reason).
You will encounter C-style strings in other people's code, but you
won't be in a position to be maintaining existing code until you've
learnt the languauge. std::string is fundamental to that.

If you want to learn C, learn C. If you want to learn C++, learn C++.
That will involve learning things like C-style strings their library
functions, but that is an advanced C++ topic.

If you want to learn C and C++ at the same time without confusing
yourself to death, you're braver than I am

GJD
 
Reply With Quote
 
A
Guest
Posts: n/a
 
      09-26-2003

> > > Ying Yang wrote:
> > >
> > > > I forgot to add that i would like to do it without using the string

data
> > > > type if possible.
> > >
> > >
> > > Why? In C++, you should strive to use std::string whenever possible,
> > > unless there is an overriding reason not to do so. Please explain your
> > > special circumstances. That will help us give an accurate answer.
> > >
> > > Brian Rodenborn

> >
> > I am learning C++ and since alot of code still contains reminants of C,

it's
> > a good idea to learn how to use functions from the older c library

before
> > moving on to the C++ library.

>
> "as well as", maybe, but not "before". As Brian said, you should be
> using std::string in your own code unless you have a very good reason
> not to (other peeple's avoidance of std::string is not a good reason).
> You will encounter C-style strings in other people's code, but you
> won't be in a position to be maintaining existing code until you've
> learnt the languauge. std::string is fundamental to that.


Point taken.


Regards
erer




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.518 / Virus Database: 316 - Release Date: 11/09/2003


 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      09-26-2003
"A" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> > Ying Yang wrote:
> >
> > > I forgot to add that i would like to do it without using the string

data
> > > type if possible.

> >
> >
> > Why? In C++, you should strive to use std::string whenever possible,
> > unless there is an overriding reason not to do so. Please explain your
> > special circumstances. That will help us give an accurate answer.
> >
> > Brian Rodenborn

>
> I am learning C++ and since alot of code still contains reminants of C,

it's
> a good idea to learn how to use functions from the older c library before


After.

> moving


>on


immediately

> to the C++ library.


-Mike


 
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
Removing duplicates and substrings from an array Sam Larbi Ruby 10 11-28-2007 10:32 PM
regex: How to extract substrings? Markus Dehmann Java 2 12-10-2005 06:35 AM
Compile typedef-ed substrings mrstephengross C++ 7 04-06-2005 06:33 PM
Using regular expressions to copy substrings into an array? Amittai Aviram Perl Misc 0 11-15-2004 06:16 AM
Binary files, substrings and (un)packing. Leandro Pardini Perl 1 10-27-2003 07:57 PM



Advertisments