字符串操作
字符串操作:
gets函数:
gets(str);
puts函数:
puts(str);
strcat函数------字符串连接函数
char str1[30] = {"apple"}; char str2[30] = {"app"}; printf("%s",strcat(str1,str2));
输出:
apple app
strcpy函数------字符串复制函数
char str1[10], str2[] = "apple"; strcpy(str1,str2); printf("%s",str1);
输出:
aaple
strcmp函数------字符串比较函数
strcmp(str1,str2);
(1):如全部字符相同,则认为字符串相等,返回 0 ;
(2):出现不相等的字符,则以第一对不相等的字符比较;"A" < "B", "A" < "a";
如果字符串 1 > 字符串 2 ,则返回 1;else 返回 - 1;
strlen函数------测字符串长度的函数
char str[10] = "apple"; int l = strlen(str);
strlwr函数------转换为小写的函数
char str[10] = "APPLE"; strlwr(str);
单个字符输入,输出:
char c = getchar(); scanf("%c",&c); printf("%c",c);
字符串输入,输出:
多个字符串输入时必须吃掉一个回车!!!
scanf("%s %s",str1,str2); printf("%s %s",str1,str2);