C语言字符串函数大全

2012-02-11 19:49:27|?次阅读|上传:wustguangh【已有?条评论】发表评论

关键词:C/C++, 字符处理|来源:唯设编程网

22.函数名: strstr

功  能: 在串中查找指定字符串的第一次出现
用  法: char *strstr(char *str1, char *str2);
程序例:

#include <stdio.h>
#include <string.h>
int main(void)
{
   char *str1 = "Borland International", *str2 = "nation", *ptr;
   ptr = strstr(str1, str2);
   printf("The substring is: %s
", ptr);
   return 0;
}

23.函数名: strtod

功  能: 将字符串转换为double型值
用  法: double strtod(char *str, char **endptr);
程序例:

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
   char input[80], *endptr;
   double value;
   printf("Enter a floating point number:");
   gets(input);
   value = strtod(input, &endptr);
   printf("The string is %s the number is %lf
", input, value);
   return 0;
}

24.函数名: strtok

功  能: 查找由在第二个串中指定的分界符分隔开的单词
用  法: char *strtok(char *str1, char *str2);
程序例:

#include <string.h>
#include <stdio.h>
int main(void)
{
   char input[16] = "abc,d";
   char *p;
   /* strtok places a NULL terminator
   in front of the token, if found */
   p = strtok(input, ",");
   if (p)   printf("%s
", p);
   /* A second call to strtok using a NULL
   as the first parameter returns a pointer
   to the character following the token  */
   p = strtok(NULL, ",");
   if (p)   printf("%s
", p);
   return 0;
}
发表评论0条 】
网友评论(共?条评论)..
C语言字符串函数大全