字符串函数
2017-08-25 13:17
190 查看
1、单字符的输入与输出
输入ctrl+z才结束。因为ctrl+z是自动结束。
strlen函数
strcmp函数
putchar int puutchar(int c); 向标准输出写一个字符。 返回写了几个字符,EOF(-1)表示写失败。 getchar int getchar(void); 向标准读入写一个字符。 返回类型是int是为了返回EOF(-1)。
#include<stdio.h> void main() { int ch; while((ch=getchar())!=EOF) { putchar(ch); } printf("EOF\n"); }
输入ctrl+z才结束。因为ctrl+z是自动结束。
strlen函数
size_t strlen(const char*s) 返回s的字符串长度(不包括0)
#include<stdio.h> #include<string.h> void main() { char line[]="hello"; printf("strlen=%lu\n",strlen(line));//长度 printf("sizeof=%lu\n",sizeof(line));//占据空间 }
strcmp函数
int strcmp(const char*s1,const char*s2); 比较两个字符串,返回 0:s1==s2 1:s1>s2 -1:s1<s2
#include<stdio.h> #include<string.h> void main() { char s1[]="hello"; char s2[]="hellp"; printf("%d\n",strcmp(s1,s2)); }
相关文章推荐
- 字符串函数
- SQL分割字符串函数
- strcpy/memcpy几个字符串函数的完美版
- ORACLE常用数值函数、转换函数、字符串函数
- float类型转换为固定小数位数的字符串函数
- Oracle字符串函数(转)
- sql server 字符串函数
- Oracle按字符截取字符串函数
- 几个典型的内存拷贝及字符串函数实现
- T-SQL常用字符串函数
- 截取字符串函数
- 分割字符串函数-ExtractStrings
- 【转载】SQL 标量函数----->字符串函数 之二 去空格函数 LTRIM() 、RTRIM()
- C语言字符串函数汇总
- C语言字符串函数大全
- C语言字符串函数大全函数名
- C语言字符串函数大全
- shell分割字符串函数(支持特殊字符和不可见字符)
- 【MYSQL】常用字符串函数2
- c#.net常用字符串函数