🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #134

Re: String Function

#134
From: Paul Lutus
Date: Sun, 14 Mar 1999 00:00
32 lines
1410 bytes
You must write it. It is not difficult. Example:

#include <stdio.h>
#include <string.h>

unsigned int countSubStrings(char *data, char *find)
{
 unsigned int count = 0;
 char *p = data;
 while((p = strstr(p,find)) != NULL) {
  count++;
  p++;
 }
 return count;
}

int main()
{
 char *test = "This is a test of a substring search algorithm.";
 char *find = "i"; /* may be multi-character */
 printf("%u occurrences of \"%s\" in
\"%s\".\n",countSubStrings(test,find),find,test);
 return 0;
}
--

Paul Lutus
www.arachnoid.com

Chris Psiuk wrote in message <36ebe918.0@news.cgocable.net>...

<snip>
Technical Details
Message-ID: <7ch2c5$dn8$1@remarQ.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <36ebe918.0@news.cgocable.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d4ba,f33d01c31aba151a
X-Google-Attributes: gid10d4ba,public
X-Google-Thread: 109fba,f33d01c31aba151a
X-Google-Attributes: gid109fba,public
X-Google-Thread: 114592,f33d01c31aba151a
X-Google-Attributes: gid114592,public
From: "Paul Lutus" <nospam@nosite.com>
Subject: Re: String Function
Date: 1999/03/14
Message-ID: <7ch2c5$dn8$1@remarQ.com>
X-Deja-AN: 454939291
References: <36ebe918.0@news.cgocable.net>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
X-Complaints-To: newsabuse@remarQ.com
X-Trace: 921439429 TQWU6NOQOE4D4D0E5C usenet52.supernews.com
Organization: Posted via RemarQ, http://www.remarQ.com - Discussions start here!
Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++