c语言处理函数 c语言中函数怎么使用( 三 )


return 0;
}
函数名: strnset
功能: 将一个串中的所有字符都设为指定字符
用法: char *strnset(char *str, char ch, unsigned n);
举例:
[cpp] view plain copy
#include stdio.h
#include string.h
int main(void)
{
char *string = "abcdefghijklmnopqrstuvwxyz";
char letter = 'x';
printf("string before strnset: %s/n", string);
strnset(string, letter, 13);
printf("string afterstrnset: %s/n", string);
return 0;
}
函数名: strpbrk
功能: 在串中查找给定字符集中的字符
用法: char *strpbrk(char *str1, char *str2);
举例:
[cpp] view plain copy
#include stdio.h
#include string.h
int main(void)
{
char *string1 = "abcdefghijklmnopqrstuvwxyz";
char *string2 = "onm";
char *ptr;
ptr = strpbrk(string1, string2);
if (ptr)
printf("strpbrk found first character: %c/n", *ptr);
else
printf("strpbrk didn't find character in set/n");
return 0;
}
函数名: strrev
功能: 串倒转
用法: char *strrev(char *str);
举例:
[cpp] view plain copy
#include string.h
#include stdio.h
int main(void)
{
char *forward = "string";
printf("Before strrev(): %s/n", forward);
strrev(forward);
printf("After strrev():%s/n", forward);
return 0;
}
/*运行结果:
Before strrev(): string
After strrev():gnirts
*/
函数名: strstr
功能: 在串中查找指定字符串的第一次出现
用法: char *strstr(char *str1, char *str2);
举例:
[cpp] view plain copy
#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/n", ptr);
return 0;
}
函数名: strtod
功能: 将字符串转换为double型值
用法: double strtod(char *str, char **endptr);
举例:
[cpp] view plain copy
#include stdio.h
#include stdlib.h
int main(void)
{
char input[80], *endptr;
double value;
printf("Enter a floating point number:");
gets(input);
value = https://www.04ip.com/post/strtod(input, endptr);
printf("The string is %s the number is %lf/n", input, value);
return 0;
}
函数名: strtol
功能: 将串转换为长整数
用法: long strtol(char *str, char **endptr, int base);
举例:
[cpp] view plain copy
#include stdlib.h
#include stdio.h
int main(void)
{
char *string = "87654321", *endptr;
long lnumber;
/* strtol converts string to long integer*/
lnumber = strtol(string, endptr, 10);
printf("string = %slong = %ld/n", string, lnumber);
return 0;
}
函数名: strupr
功能: 将串中的小写字母转换为大写字母
用法: char *strupr(char *str);
举例:
[cpp] view plain copy
#include stdio.h
#include string.h
int main(void)
{
char *string = "abcdefghijklmnopqrstuvwxyz", *ptr;
/* converts string to upper case characters */
ptr = strupr(string);
printf("%s/n", ptr);
return 0;
}
c语言时间处理函数C语言的标准库函数包括一系列日期和时间处理函数,它们都在头文件中说明 。
在头文件中定义了三种类型:time_t , struct tm和clock_t 。
下面列出了这些函数 。
time_t time(time_t *timer);
double difftime(time_t time1,time_t time2);
struct tm *gmtime(const time_t *timer);
struct tm *localtime(const time_t *timer);
char *asctime(const struct tm *timeptr);
char *ctime(const time_t *timer);
size_t strftime(char *s,size_t maxsize,const char *format,const struct tm *timeptr);

推荐阅读