![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
字符串
ni_darling
这个作者很懒,什么都没留下…
展开
-
4. 字符串函数 strlen() strcat() strncat() strcmp() strncmp() strcpy() strncpy() sprintf()...
1. strlen#include <stdio.h>#include <string.h>void fit(char *buf, int size){ if(strlen(buf) > size) { buf[size] = '\0'; }}int main(int argc, char const *argv[]){ char buf[] = "point storage string."; //这里必须要声明成数组表示法,因为指针表示法不原创 2020-09-21 01:09:08 · 252 阅读 · 0 评论 -
3. 字符串输出puts() fputs() printf()
puts() 函数puts() 函数只需要把字符串的地址作为参数传递给它即可。#include <stdio.h>#define MSG "i am a string"int main(int argc, char const *argv[]){ char *str1 = "point storage string."; char str2[40] = "array storage string."; puts(MSG); puts(str1); puts(str2)..原创 2020-09-08 23:25:30 · 470 阅读 · 0 评论 -
2. 字符串输入 gets() fgets() scanf()
gets() 函数(dangerous and should not be used)scanf() 和转换说明 %s 只能读取一个单词,不支持读取一整行输入,gets() 函数可以读取整行输入,然后丢弃换行符,储存其余字符,并在末尾加上一个空白字符使其成为一个字符串。他经常与puts() 函数配合使用,puts() 函数用于显示字符串,并在末尾加上换行符。例子:#include <stdio.h>#define LEN 10int main(int argc, char co..原创 2020-09-08 23:24:28 · 519 阅读 · 0 评论 -
1. 字符串 字符串数组
1. 字符串#include <stdio.h>#define MSG "I am a symbolic string constant."#define MAXLEN 81int main(int argc, char const *argv[]){ char words[MAXLEN] = "I am a string in an array."; char *ptr1 = "Something is pointing at me."; puts("Here are s原创 2020-09-05 11:21:05 · 3392 阅读 · 0 评论