TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Frank Adam
from: Paul Edwards
date: 1996-06-08 13:00:38
subject: Find a word

FA> char* In_Str(char *buf,char *wrd)  /* case insensitive strstr() */
FA> {
FA>  char *txt;char *pat;char *ptr;
FA>  txt = (char*) malloc(strlen(buf)+1);
FA>  pat = (char*) malloc(strlen(wrd)+1);

These malloc's are very wasteful, why don't you write your own
strstr which is case-insensitive?

From PDPCLIB (FREQ it if you don't have it)...

/*********************************************************************/
/*                                                                   */
/*  This Program Written by Paul Edwards, 3:711/934{at}fidonet.         */
/*  Released to the Public Domain                                    */
/*                                                                   */
/*********************************************************************/
/*********************************************************************/
/*                                                                   */
/*  string.c - implementation of routines in string.h                */
/*                                                                   */
/*********************************************************************/

#include "string.h"

int strncmp(const char *s1, const char *s2, size_t n)
{
    const unsigned char *p1;
    const unsigned char *p2;
    size_t x = 0;
    
    p1 = (const unsigned char *)s1;
    p2 = (const unsigned char *)s2;
    while (x < n)
    {
        if (p1[x] < p2[x]) return (-1);
        else if (p1[x] > p2[x]) return (1);
        else if (p1[x] == '\0') return (0);
        x++;
    }
    return (0);
}

char *strstr(const char *s1, const char *s2)
{
    size_t len;
    const char *p;

    len = strlen(s2);    
    p = s1;
    while (*p != '\0')
    {
        if (strncmp(p, s2, len) == 0) return ((char *)p);
        p++;
    }
    return (NULL);
}
@EOT:

---
* Origin: X (3:711/934.9)

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.