c 字符串处理
程序开头要声明
#include <string.h>
函数名: stpcpy
功 能: 拷贝一个字符串到另一个
用 法: char *stpcpy(char *destin, char *source);
程序例:
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[10];
char *str1 = "abcdefghi";
stpcpy(string, str1);
printf("%s\n", string);
return 0;
}
函数名: strcat
功 能: 字符串拼接函数
用 法: char *strcat(char *destin, char *source);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char destination[25];
char *blank = " ", *c = "C++", *Borland = "Borland";
strcpy(destination, Borland);
strcat(destination, blank);
strcat(destination, c);
printf("%s\n", destination);
return 0;
}
函数名: strchr
功 能: 在一个串中查找给定字符的第一个匹配之处\
用 法: char *strchr(char *str, char c);
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char string[15];
char *ptr, c = 'r';
strcpy(string, "This is a string");
ptr = strchr(string, c);
if (ptr)
printf("The character %c is at position: %d\n", c, ptr-string);
else
printf("The character was not found\n");
return 0;
}
函数名: strcmp
功 能: 串比较
用 法: int strcmp(char *str1, char *str2);
看Asic码,str1>str2,返回值 > 0;两串相等,返回0
程序例:
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
int ptr;
ptr = strcmp(buf2, buf1);
if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n");
else
printf("buffer 2 is less than buffer 1\n");
ptr = strcmp(buf2, buf3);
if (ptr > 0)
printf("buffer 2 is greater than buffer 3\n");
else
相关文档:
内容介绍
本系列文章根据《单元测试与VU2.6应用》视频讲座的理论部分整理而成,主要讨论四个问题:为什么需要单元测试?怎样征服可测性难题?怎样才能高效率测试?怎样保证测试效果?重点阐述单元测试的关键问题,不是一般概念,适合于对单元测试有一定了解的读者。
在选择工具和实施 ......
我觉得,在输入输出函数中,scanf()函数,应该是最麻烦的,有时它给我们的结果很可笑,但是一定是一原因的....
首先声明一下,这篇日志不是介绍scanf()中各种格式符用法的文章(没有这个必要,但是大家一定要会用).
我尝试了很多种输入,包括一些错误的练习,曾经对scanf()由迷茫转向清醒,又由清醒再次转向迷茫......不知道何时是个 ......
当你买了台新电脑时,觉得性能,速度,你都比较满意,但是随着时间推移,你觉得你C盘空间越来越小,速度也降下了,那我们该怎么办呢?
对于菜鸟来说,有一点你必须注意:当你下载东西,有些网站是默认C盘,这时可以选择下载盘时,最好放在其他盘里,不可以选择也没办法,C盘里的文件也是病毒喜欢 ......