前言:
目前各位老铁们对“c语言和e语言”大概比较珍视,同学们都需要了解一些“c语言和e语言”的相关资讯。那么小编同时在网络上网罗了一些有关“c语言和e语言””的相关文章,希望咱们能喜欢,姐妹们一起来学习一下吧!分享兴趣,传播快乐,增长见闻,留下美好!
亲爱的您,这里是LearningYard新学苑。
今天小编为大家带来
“学越千山:C语言程序设计练习题(九)”,
欢迎您的访问。
Share interests, spread happiness, increase knowledge, and leave behind beauty!
Dear you, this is LearningYard New School.
Today, the editor bringv you
Learning to Cross a Thousand Mountains:
C Language Programming Exercise
Quesvtion (9),
Welcome to visit.
思维导图
Mind mapping
字符串
Character String
即有若干有效字符构成且以字符“\0”结尾的一个字符序列。
其实我们早已接触过字符串了,例如:printf("1536")这里的1536就是字符串,在C语言系统中,这条语句输出时会自动补充“\0”。
但C语言中没有提供字符串的数据类型,因此这里借助数组来实现字符串的存取。
定义:char str[i];
A character sequence consisting of several valid characters and ending with the character ' 0'.
In fact, we have already been exposed to strings, such as printf ("1536") where 1536 is a string. In the C language system, when this statement is output, it will automatically be supplemented with " 0".
However, C language does not provide a data type for strings, so arrays are used here to access strings.
Definition: char str [i];
初始化
Initialization
(1)用字符常量初始化
char str[6]={'a','b','c','d','e','\0'};
(2)用字符串常量初始化
char str[6]={"abcde"};
char str[6]="abcde";
//初始化一维字符型数组,可不用{}
char str[]="abcde";
(1) Initialize with character constants
Char str [6]={'a ',' b ',' c ','d', 'e', ' 0'};
(2) Initialize with string constants
Char str [6]={"abcde"};
Char str [6]="abcde";
//Initialize a one-dimensional character array without {}
Char str []="abcde";
字符串的访问与输出
Access and output of strings
(1)一个一个输入输出
(1) One input and one output
(2)整体输入输出
(2) Overall input and output
字符串的复制
函数形式:
strcpy(str2,str1);
//注意方向,将str1的值复制给str2,同时str2必需足够大,避免数据溢出
//不能整体复制
Functional form:
Strcpy (str2, str1);
//Pay attention to the direction, copy the value of str1 to str2, and str2 must be large enough to avoid data overflow
//Cannot replicate as a whole
字符串的连接
String connection
函数形式:
strcat(str2,str1);
//注意方向,将str1的值接在str2后,同时str2必需足够大,避免数据溢出
Functional form:
Strcat (str2, str1);
//Pay attention to the direction and place the value of str1 after str2, while str2 must be large enough to avoid data overflow
字符串的比较
Comparing strings
函数形式:
strcmp(str2,str1);
//字符串不能用“<”,“>”,“=”比较,用Ascll码。
Functional form:
Strcmp (str2, str1);
//String cannot be compared with '<', '>', '=', use Ascll code.
(具体的函数程序将在练习十给出)
(The specific function program will be given in Exercise 10)
今天的分享就到这里了,
如果您对文章有独特的想法,
欢迎给我们留言。
让我们相约明天,
祝您今天过得开心快乐!
That's all for today's sharing,
If you have unique ideas about the article,
Welcome to leave us a message.
Let's make an appointment tomorrow,
Wishing you a happy and joyful day!
参考资料:百度翻译,C语言程序设计第4版(苏小红等)
本文由LearningYard新学苑整理并发出,如有侵权请后台留言沟通
标签: #c语言和e语言