strpref.c

来自「Many C samples. It is a good sample for 」· C语言 代码 · 共 26 行

C
26
字号
/*  File   : strpref.c
    Author : Richard A. O'Keefe.
    Updated: 11 April 1984
    Defines: strpref()

    strpref(src, prefix)
    checks whether prefix is a prefix of src.  If it is not, the  result
    is  NullS.  If it is, the result is a pointer to the first character
    of src after the prefix (src+strlen(prefix)).  You can use this in a
    conditional as a test: if (strpref(....)), but this is only portable
    provided you remember to declare strpref() properly or use strings.h
    as if (...) tests numbers against 0 and pointers against a suitable
    cast of 0; there is no guarantee that (char*)0 is represented by the
    same bit pattern as (int)0.
*/

#include "strings.h"

char *strpref(src, prefix)
    register char *src, *prefix;
    {
	while (*prefix) if (*src++ != *prefix++) return NullS;
	return src;
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?