C测试小程序
C测试小程序
1、 字符串类
1.1 strstr
功能:查找和获取子串
void test_strstr()
{
char *str="Borland International";
char *str1="B",*ptr1;
char *str2="na",*ptr2;
char *str3="",*ptr3;
ptr1=strstr(str,str1);
printf("The substring1 is: %s\n", ptr1);//Borland International
ptr2=strstr(str,str2);
printf("The substring2 is: %s\n", ptr2);//national
ptr3=strstr(str,str3);
printf("The substring3 is: %s\n", ptr3); //Borland International
}
/*****************************************************
char *strstr( const char *string, const char *strCharSet );
Each of these functions returns a pointer to the first occurrence of strCharSet in string,
or NULL if strCharSet does not appear in string. If strCharSet points to a string of zero length,
the function returns string.
******************************************************/
1.2 atoi和_itoa
功能:char和int之间的互相转换
void char2int_1()
{
char* temp1="123";
int a1=atoi(temp1);
printf("char2int_1()\ta1+1=%
相关文档:
利用c.vim插件,你可以实现
添加文件头
添加注释
插入一些代码片段
语法检查
读函数文档
注释代码块
这一插件的作者是 Fritz Mehner, 目标就是打造程序员流畅的编辑环境。
这一插件还能完成:
Statement oriented editing of C / C++ programs
Speed up writing new code considerably.
Write code and ......
#include
#include
#include
/*
* 翻转
*/
char *mystrrev(char *arr)
{
if (!arr)
{
return NULL;
}
char *temp = arr;
char t;
int leng = strlen(arr) + 1;
int l = (int)(leng / 2);
int i = 0;
while (l--)
{
t = arr[i];
arr[ ......
前天写一个小程序, 突然发现其实偶的C学的不怎么样啊,好多函数都不记得,在网上搜到的都是些乱七八糟的,没有原型,用起来不放心,用E文搜,搜到真正的Bible——
The GNU C Library Manual
这里面太全了,只是有一点不太好,E文的,读起来有点慢,感觉有点浪费时间
用C写了段小程序把一个五笔码文本文档转 ......
C语言中有几个基本输入函数:
//获取字符系列
int fgetc(FILE *stream);
int getc(FILE *stream);
int getchar(void);
//获取行系列
char *fgets(char * restrict s, int n, FILE * restrict stream);
char *gets(char *s);//可能导致溢出,用fgets代替之。
//格式化输入系列
int fscanf(FILE * r ......
#include
#include
#include
#include
#include
#include
#include
typedef struct worker
{
int num; //编号
char name[15]; //姓名
char zhicheng[15];& ......