文史百科-中国历史

 文史百科-中国历史     |      2019-11-30

 

 

#include<string.h>

}

 

 

找出str2字符串在str1字符串中第一次出现的位置(不包括str2的串结束符)。返回该位置的指针,如找不到,返回空指针。

   int ptr;

DEMO: mystrstr

 

 

    length = strcspn(string1, string2);

  1. //#define FIRST_DEMO  
  2. #define SECOND_DEMO  
  3.   
  4. #ifdef FIRST_DEMO  
  5. #include <stdio.h>  
  6. #include <conio.h>  
  7. #include <string.h>  
  8. int main(void)  
  9. {  
  10.     char *s="Golden Global View";  
  11.     char *l="lob";  
  12.     char *p;  
  13.     system("cls");  
  14.     p=strstr(s,l);  
  15.     if (p!=NULL)  
  16.     {  
  17.         printf("%sn",p);  
  18.     }  
  19.     else  
  20.     {  
  21.         printf("Not Found!n");  
  22.     }  
  23.   
  24.     getch();  
  25.     return 0;  
  26. }  
  27. #elif defined SECOND_DEMO  
  28. /*从字串” string1 onexxx string2 oneyyy”中寻找”yyy”*/  
  29. #include <stdio.h>  
  30. #include <conio.h>  
  31. #include <string.h>  
  32. int main(void)  
  33. {  
  34.     char *s="string1 onexxx string2 oneyyy";  
  35.     char *p;  
  36.     p=strstr(s,"string2");  
  37.     printf("%sn",p);  
  38.     if (p==NULL)  
  39.     {  
  40.         printf("Not Found!n");  
  41.     }  
  42.     p=strstr(p,"one");  
  43.     printf("%sn",p);  
  44.     if (p==NULL)  
  45.     {  
  46.         printf("Not Found!n");  
  47.     }  
  48.     p+=strlen("one");  
  49.     printf("%sn",p);  
  50.   
  51.     getch();  
  52.     return 0;  
  53. }  
  54. #endif   

#include <string.h>

Returns a pointer to the first occurrence of strSearch in str, or NULL if strSearch does not appear in str. If strSearch points to a string of zero length, the function returns str.

   return 0;

【FROM MSDN && 百科】

   return 0;

原型:char *strstr(const char *str1, const char *str2);

看Asic码,str1>str2,返回值 > 0;两串相等,返回0

程序例:

 

#include <string.h>

#include <stdio.h>

   return 0;

   int ptr;

 

功 能: 串拷贝

   return 0;

 

#include <string.h>

 

用 法: char *strdup(char *str);

   strset(string, symbol);

功 能: 串比较

 

程序例:

 

   if (ptr > 0)

 

 

   return 0;

   printf("After strrev(): %sn", forward);

   return 0;

功 能: 拷贝一个字符串到另一个

int main(void)

{

 

   char *ptr;

用法:token = strtok(source-str,seperator-str)
用途:在source-str中找出以seperator-str中的字符为分隔的字符串,即是源串中除去了含有分隔串中的所有字符后余下的一段段的字符串,每调用一次找到一串,找不到则返回空串。
注意:返回值是指向源串的指针,所以同样要保证源串的有效性,此外,每次调用返回找到的子串的时候都会把源串中该子串的尾部字符(原来是搜索串中的某一字符)修改成''字符。还有一个要注意的是,这个函数使用全局的静态缓冲区(函数自己的静态buffer),所以在某一个线程里不要同时调用这个函数来处理两个字符串,否则极易出现不正常的结果,正确的处理方法是先找出一个字符串中的所有子串,然后才转到处理另一个字符串。多线程之间则不会出现这种干扰。
同样举MSDN中的例子:
数据准备:
char string[] = "A stringtof ,,tokensnand some  more tokens";
char seps[]   = " ,tn";
char *token;
调用示例:
   token = strtok( string, seps );
   while( token != NULL )
   {
      /* While there are tokens in "string" */
      printf( " %sn", token );
      /* Get next token: */
      token = strtok( NULL, seps );
/*注意到上面这个NULL,它表明的是从上次调用结果中strtok自有的缓冲区中继续取出余下的子串*/
   }
显示结果:
 A        //此时string[1]='',原先为空格
 string
 of
 tokens
 and
 some
 more
 tokens

   char *buf1 = "BBBccc", *buf2 = "bbbccc";

   char input[80], *endptr;

函数名: strncmpi

      printf("The character was not foundn");

 

 

函数名: stpcpy

用 法: int stricmp(char *str1, char *str2);

    int ptr;

 

 

程序例:

 

   printf("This is target: %sn", target);

函数名: stricmp

 

   in front of the token, if found */

功 能: 将一个串中的一部分与另一个串比较, 不管大小写

 

 

   char *buf1 = "BBBccc", *buf2 = "bbbccc";

}

      printf("buffer 2 equals buffer 1n");

用 法: int strncmp(char *str1, char *str2, int maxlen);

 

 

 

 

{

 

 

功 能: 串拷贝

   ptr = strpbrk(string1, string2);

程序例:

   else

函数名: strncmp

程序例:

int main(void)

程序例:

 

   p = strtok(input, ",");

   ptr = strnicmp(buf2, buf1, 3);

    if (ptr)

#include <stdio.h>

#include <string.h>

int main(void)

    char string[15];

   char *str1 = "Borland International", *str2 = "nation", *ptr;

   printf("The string is %s the number is %lfn", input, value);

    char string[10];

 

    printf("%sn", dup_str);

#include <stdio.h>

 {

    return 0;

   if (ptr > 0)

功 能: 在串中查找第一个给定字符集内容的段

功 能: 将一个串中的所有字符都设为指定字符

   if (ptr > 0)

程序例:

 

   else

程序例:

   lnumber = strtol(string, &endptr, 10);

      printf("buffer 2 is greater than buffer 1n");

   return 0;

程序例:

   return 0;

 

   char string[10];

 

功 能: 串比较

   double value;

}

用 法: int strcmpi(char *str1, char *str2);

用 法: char *strstr(char *str1, char *str2);

    char *dup_str, *string = "abcde";

#include <stdio.h>

程序例:

   char letter = 'x';

   ptr = strncmp(buf2,buf3,3);

{

 

{

   if (ptr == 0)

用 法: double strtod(char *str, char **endptr);

#include <string.h>

{

#include <stdio.h>

   printf("After strset(): %sn", string);

   char string[15];

 

#include <stdio.h>

   printf("%sn", ptr);

}

#include <string.h>

功 能: 将一个串中的所有字符都设为指定字符

用 法: char *strrchr(char *str, char c);

 

int main(void)

 

 

 

int main(void)

 

用 法: char *strnset(char *str, char ch, unsigned n);

{

程序例:

   if (ptr)

函数名: strnicmp

 

 

功 能: 在串中查找指定字符的最后一个出现

{

int main(void)

int main(void)

 

 

 }

#include <string.h>

 

 

int main(void)

}

   if (ptr)

 

   ptr = strncmpi(buf2,buf1,3);

#include <string.h>

 

int main(void)

 

 

    free(dup_str);

 

    ptr = strcmp(buf2, buf3);

函数名: strspn

int main(void)

   char *buffer;

 

 

 

   return 0;

      printf("buffer 2 is greater than buffer 1n");

   buffer = strerror(errno);

 

 

#include <string.h>

int main(void)

功 能: 字符串拼接函数

 

{

#include <string.h>

功 能: 将字符串转换为double型值

 

功 能: 将串拷贝到新建的位置处

 

#include <string.h>

 

#include <stdio.h>

用 法: char *strcpy(char *str1, char *str2);

 

 

#include <stdio.h>

 

      printf("buffer 2 is greater than buffer 1n");

用 法: int strspn(char *str1, char *str2);

   printf("string after strnset: %sn", string);

 

}

 

 

 

 

#include <stdio.h>

 

程序例:

 

 

程序例:

   ptr = strcmpi(buf2, buf1);

 {

   char *buf1 = "BBB", *buf2 = "bbb";

 

 

 

   int ptr;

程序例:

 

 

函数名: strupr

 

RETURN VALUES

The function strncasecmp() returns a positive integer if, within the first n bytes of string s1 and string s2, disregarding case string s1 is lexically greater than string s2. It returns zero if, other than case, the first n bytes of the two strings are identical. Finally, strncasecmp() returns a negative integer if with the first n bytes, disregarding case string s1 is lexically less than string s2.


程序例:

  

功 能: 将串转换为长整数

      printf("buffer 2 is less than buffer 1n");

int main(void)

    char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";

 

 

 

 

 

#include <string.h>

   char *string1 = "abcdefghijklmnopqrstuvwxyz";

   ptr = strrchr(string, c);

#include <string.h>

 -----------------------

   char *blank = " ", *c = "C++", *Borland = "Borland";

   printf("The substring is: %sn", ptr);

    return 0;

 

 

int main(void)

 

      printf("buffer 2 is less than buffer 1n");

   ptr = strncmp(buf2,buf1,3);

      printf("buffer 2 equals buffer 1n");

 

    int length;

}

       printf("The character was not foundn");

    char *str1 = "abcdefghi";

char target[15];

 

   char *buf1 = "BBB", *buf2 = "bbb";

 {

#include <stdio.h>

 

 

 

      printf("buffer 2 equals buffer 1n");

   char *str1 = "abcdefghi";

 

程序例:

#include <stdlib.h>

 

 

 

函数名: strcmpi

 

   char input[16] = "abc,d";

功 能: 在串中查找指定字符串的第一次出现

}

   char string[10] = "123456789";

用 法: char *strset(char *str, char c);

   printf("Before strset(): %sn", string);

   if (p)   printf("%sn", p);

#include <stdio.h>

   return 0;

int main(void)

   printf("%sn", string);

 

#include <string.h>

函数名: strpbrk

}

#include <string.h>

用 法: int strcspn(char *str1, char *str2);

功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写

   char destination[25];

    char *ptr, c = 'r';

   return 0;

函数名: strcat

   return(0);

 

 

   int length;

   return 0;

   ptr = stricmp(buf2, buf1);

 

 

 

{

    printf("%sn", string);

 

      printf("buffer 2 equals buffer 1n");

程序例:

 

函数名: strrchr

 

 

PORTING ISSUES

None.


   if (ptr > 0)

#include <errno.h>

 

int main(void)

   swab(source, target, strlen(source));

 

int main(void)

    char *string1 = "1234567890";

 

 

 

   strcat(destination, blank);

函数名: strrev

   length = strspn(string1, string2);

 

功 能: 将一个串与另一个比较, 不管大小写

 }

   return 0;

 

#include <stdlib.h>

 

函数名: strset

   ptr = strstr(str1, str2);

 

#include <stdio.h>

 

 

 }

SYNOPSIS

#include <string.h>

int strncasecmp(const char *s1, const char *s2, size_t n);


用 法: void swab (char *from, char *to, int nbytes);

#include <alloc.h>

 

功 能: 以大小写不敏感方式比较两个串

功 能: 在串中查找指定字符集的子集的第一次出现

int main(void)

函数名: strerror

 

   printf("Enter a floating point number:");

   char *ptr, c = 'r';

 

 

 

#include <string.h>

}

函数名: strchr

 

 

 

   if (ptr > 0)

 

函数名: strcmp

      printf("buffer 2 is less than buffer 1n");

 {

 

 

 

#include <stdlib.h>

功 能: 查找由在第二个串中指定的分界符分隔开的单词

  

{

    ptr = strcmp(buf2, buf1);

      printf("buffer 2 equals buffer 1n");

程序例:

 

}

    return 0;

 

AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


功 能: 交换字节

 

       printf("buffer 2 is greater than buffer 1n");

#include <stdio.h>

 

 

int main(void)

   char *forward = "string";

MULTITHREAD SAFETY LEVEL

MT-Safe.


int main(void)

函数名: strtok

#include <stdio.h>

   char *p;

   if (ptr < 0)

   char *string = "87654321", *endptr;

 C语言字符串函数大全

用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);

}

函数名: strtod

程序例:

int main(void)

 

{

    printf("Character where strings intersect is at position %dn", length);

   printf("%sn", string);

 

#include <stdio.h>

 

 

      printf("buffer 2 is greater than buffer 1n");

 

函数名: strtol

    strcpy(string, "This is a string");

{

   char *buf1 = "BBB", *buf2 = "bbb";

用 法: char *strpbrk(char *str1, char *str2);

 

 

 

 

   if (ptr > 0)

 

#include <stdio.h>

#include <stdio.h>

   return 0;

}

}

{

程序例:

   printf("string = %s long = %ldn", string, lnumber);

用 法: int strcmp(char *str1, char *str2);

   if (ptr < 0)

 

      printf("strpbrk didn't find character in setn");

{

 

   printf("%sn", destination);

       printf("buffer 2 is less than buffer 3n");

    else

 

   char *string = "abcdefghijklmnopqrstuvwxyz", *ptr;

   int ptr;

#include <stdio.h>

#include <alloc.h>

int main(void)

 

   printf("Error: %sn", buffer);

int main(void)

    return 0;

 

    dup_str = strdup(string);

      printf("The character %c is at position: %dn", c, ptr-string);

}

    char *string2 = "747DC8";

用 法: char *strrev(char *str);

函数名: strncmpi

       printf("buffer 2 is less than buffer 1n");

{

   if (p)   printf("%sn", p);

用 法: char *strncpy(char *destin, char *source, int maxlen);

   if (ptr < 0)

函数名: strcpy

 }

   /* strtok places a NULL terminator

 

功 能: 返回指向错误信息字符串的指针

Function

SYNOPSIS DESCRIPTION PARAMETERS RETURN VALUES CONFORMANCE MULTITHREAD SAFETY LEVEL PORTING ISSUES AVAILABILITY SEE ALSO


用 法: long strtol(char *str, char **endptr, int base);

用 法: char *strupr(char *str);

      printf("buffer 2 is greater than buffer 1n");

 

 

   else

{

   char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";

用 法: char *strerror(int errnum);

功 能: 将串中的小写字母转换为大写字母

 

   printf("string before strnset: %sn", string);

   char *string2 = "onm";

   return 0;

   return 0;

程序例:

功 能: 不注重大小写地比较两个串

   return 0;

 

   int ptr;

 

 

 

   string[3] = '';

 

int main(void)

   int ptr;

 

函数名: strncpy

strncasecmp()

compare part of two strings, ignoring case 

   else

   value = strtod(input, &endptr);

用 法: int strncmpi(char *str1, char *str2, unsigned maxlen);

#include <alloc.h>

   /* strtol converts string to long integer */

   strcpy(destination, Borland);

#include <stdio.h>

{

 

{

   strcat(destination, c);

#include <stdio.h>

函数名: strnset

   char *str1 = "abcdefghi";

}

   return 0;

 

调用格式:result = strpbrk(source-string, searching-string)
用途:在源字符串(source-string)中找出最先含有搜索字符串(searching-string)中的任一字符的位置并返回,若找不到则返回空指针。
注意:返回值是指向源字符串的指针,所以在使用返回结果的时候,请确保源字符串的有效性。
举MSDN中的例子:
数据:
char string[100] = "The 3 men and 2 boys ate 5 pigsn";
char *result;
调用:
result = strpbrk( string, "0123456789" );//在string中找出最先出现0~9中某一个字符的位置
printf( "1: %sn", result++ );
result = strpbrk( result, "0123456789" );
printf( "2: %sn", result++ );
result = strpbrk( result, "0123456789" );
printf( "3: %sn", result );
输出的结果是:
1. 3 men and 2 boys ate 5 pigs//最先发现3

2: 2 boys ate 5 pigs//最先发现2,注意这时开始源串是上一次的结果的下一位置,即跳过了数字'3',下同

3: 5 pigs//最先发现5

 

用 法: char *strchr(char *str, char c);

      printf("buffer 2 is less than buffer 1n");

 

 

 

   ptr = strupr(string);

 

     

 

 

用 法: char *strcat(char *destin, char *source);

int main(void)

int main(void)

   return 0;

       printf("The character %c is at position: %dn", c, ptr-string);

 

char source[15] = "rFna koBlrna d";

CONFORMANCE

UNIX 98.


函数名: strcspn

 

 

   to the character following the token */

   p = strtok(NULL, ",");

   if (ptr == 0)

      printf("buffer 2 is less than buffer 1n");

}

 

#include <string.h>

#include <stdio.h>

}

用 法: char *strtok(char *str1, char *str2);

 

{

 

 

 

 

   if (ptr < 0)

    ptr = strchr(string, c);

   char *string = "abcdefghijklmnopqrstuvwxyz";

int main(void)

   if (ptr == 0)

   /* converts string to upper case characters */

程序例:

 

#include <string.h>

   if (ptr == 0)

PARAMETERS

s1 
Points to a string to compare.

s2 
Points to a string to compare.

n 
Is the maximum number of characters to compare.

 


 

}

   return 0;

   char symbol = 'c';

   long lnumber;

{

 

      printf("buffer 2 is greater than buffer 1n");

   as the first parameter returns a pointer

 

 

 

函数名: strdup

#include <string.h>

      printf("strpbrk found first character: %cn", *ptr);

功 能: 在串中查找给定字符集中的字符

      printf("buffer 2 is greater than buffer 3n");

 

 

程序例:

   /* A second call to strtok using a NULL

    else

#include <string.h>

 

   char string[10];

 

 

 

 

    return 0;

#include <string.h>

程序例:

 

   gets(input);

#include <string.h>

函数名: strstr

      printf("buffer 2 is less than buffer 3n");

   strrev(forward);

 

   if (ptr < 0)

函数名: swab

   stpcpy(string, str1);

int main(void)

#include <stdio.h>

程序例:

#include <stdio.h>

}

  if (ptr > 0)

   return 0;

 

 

    strcpy(string, str1);

      printf("buffer 2 is less than buffer 1n");

 

用 法: char *stpcpy(char *destin, char *source);

 

}

 

   if (ptr == 0)

#include <string.h>

用 法: int strncmpi(char *str1, char *str2);

程序例:

功 能: 串倒转

 

DESCRIPTION

The function strncasecmp() performs a case-insensitive string comparison for up to the first n characters of the strings pointed to by s1 and s2.


 

 

#include <stdio.h>

   strcpy(string, "This is a string");

 

 

 

#include <string.h>

 {

#include <stdio.h>

       printf("buffer 2 is greater than buffer 3n");

 

   char *string1 = "1234567890";

程序例:

 

 

   char *string2 = "123DC8";

 

#include <stdio.h>

功 能: 在一个串中查找给定字符的第一个匹配之处

   strncpy(string, str1, 3);

   printf("Character where strings differ is at position %dn", length);

 

   ptr = strcmpi(buf2, buf1);

   printf("Before strrev(): %sn", forward);

    if (ptr > 0)

 }

 

 

}

 

{

    else

 

    if (ptr > 0)

   strnset(string, letter, 13);

{

 ------------------------

#include <stdio.h>