view mc09/string.txt @ 180:c3145f913f3d default tip

possible features
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 04 May 2019 11:17:42 +0900
parents 1a30cd6e5973
children
line wrap: on
line source


strcat(s,t)
char *s,*t;
{       while (*s) ++s;
        strcpy(s,t);
}

strcmp(s,t)
char *s,*t;
{       for (; *s == *t; ++s,++t) if (!*s) break;
        return (*s - *t);
}

strcpy(s,t)
char *s,*t;
{       while (*s++ = *t++);
}

char *gets(s,n)
char *s;
int n;
{       return fgets(s,n,stdin);
}

puts(s)
char *s;
{       return fputs(s,stdout);
}

char *fgets(s,n,f)
char *s,*f;
int n;
{char c,*t;
        t = s;
        while (--n > 0)
        {       if ((c = getc(f)) == EOF) break;
                if ((*s++ = c) == '\n') break;
        }
        *s = '\0';
        return ((c == EOF && s == t) ? NULL : s);

}

fputs(s,f)
char *s,*f;
{       while (*s) putc(*s++,f);
}

match(p,s)
char *p,*s;
{       switch (*p)
        {case '*':
                if (!*(p+1)) return 1;
                while (!match(p+1,s)) if (!*s++) return 0;
                return 1;
         case '?':
                return (*s ? match(p+1,s+1) : 0);
         case '\0':
                return (!*s);
         default:
                if (*p == *s) return match(p+1,s+1);
                return 0;
        }
}