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
相关文档:
{
SqlConnection cnn = new SqlConnection
("context connection=true");
cnn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cnn;
cmd.CommandText = "select * from customers";
SqlDataReader reader = cmd.ExecuteReader();
SqlContext.Pipe.Send(reader);
reader.Close();
cnn.Close();
}
......
[C/C++ Digestion] – Rule of Three,
复制控制
作者:
Jason Lee @
http://blog.csdn.net/jasonblog
日期:
2010-04-13
[1]
复制构造函数
copy constructor
Rule of Three
是指类如果需要析构函数,则通常也需要复制构造函数和赋值操作符。而其实习惯地显示编写这三者本就是一个良好的习惯。因 ......
C专家编程 精编之一 第一章~第三章
C的复杂之处 在于它的指针 ,但是比其指针更为复杂的是它的声明 !!!
你能看懂它们的意思 吗?
apple=sizeof(int)*p ; apple=sizeof * p;
j= (char (*)[20])malloc(20);
int const * grape; 与 int * const gr ......
当你买了台新电脑时,觉得性能,速度,你都比较满意,但是随着时间推移,你觉得你C盘空间越来越小,速度也降下了,那我们该怎么办呢?
对于菜鸟来说,有一点你必须注意:当你下载东西,有些网站是默认C盘,这时可以选择下载盘时,最好放在其他盘里,不可以选择也没办法,C盘里的文件也是病毒喜欢 ......