易截截图软件、单文件、免安装、纯绿色、仅160KB

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


相关文档:

C字符串处理函数的实现

C字符串处理函数的实现(Linux)
#include <stddef.h>
char * ___strtok = NULL;
char * strcpy(char * dest,const char *src)
{
char *tmp = dest;
while ((*dest++ = *src++) != '\0')
/* nothing */;
return tmp;
}
char * strncpy(char * dest,const char *src,size_t count)
{
char *tmp = d ......

C/C++定义全局变量/常量几种方法的区别

. 编译单元(模块):
    在IDE开发工具大行其道的今天,对于编译的一些概念很多人已经不再清楚了,很多程序员最怕的就是处理连接错误(LINK ERROR), 因为它不像编译错误那样可以给出你程序错误的具体位置,你常常对这种错误感到懊恼,但是如果你经常使用gcc,makefile等工具在linux或者嵌入式下做开发工作的 ......

C Error: mixed declaration and codes.

/*FIXME
ISO C如果你在main()中写代码的中间定义了一个对于main而言的全局变量,就会报出这个错误。
*/
把这个变量定义到main函数中的最前方,就会修正这个错误。
而且为了防止出错,设定的指针之后再有参数传入malloc之后立即对于指针予以空间的创建。防止出现指针未初始化从而引起将来赋值的时候将该值覆盖了已经为本 ......

Linux下的C编程实战之文件系统编程

文章来源:http://dev.yesky.com/468/7601968.shtml
2007-10-12 11:01作者:宋宝华出处:天极网软件频道责任编辑:方舟
1.Linux文件系统
  Linux支持多种文件系统,如ext、ext2、minix、iso9660、msdos、fat、vfat、nfs等。在这些具体文件系统的上层,Linux提供了虚拟文件系统(VFS)来统一它们的行为,虚拟文件系统为 ......

Linux下的C编程入门之“线程”控制与“线程”通信编程

本文来自:Linux教程 -- http://doc.linuxpk.com/53295.html
如有不明白之处,欢迎参加社区讨论
1.Linux“线程”
 笔者曾经在《基于嵌入式操作系统VxWorks的多任务并发程序设计》(《软件报》2006年第5~12期)中详细叙述了进程和线程的区别,并曾经说明Linux是一种“多进程单线程”的操作系统。 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号