C语言字符串的存储、初始化
- 字符串,是通过“字符数组”(元素类型为char的数组)来存储的!
demo
#include <stdio.h>
#include <Windows.h>
int main(void) {
char name1[32];
name1[0] = 'C';
name1[1] = 'a';
name1[2] = 'm';
name1[3] = 'e';
name1[4] = 'l';
name1[5] = '\0';
printf("%s\n", name1);
char name2[32] = "Camel";
printf("%s\n", name2);
char name3[] = "Camel";
printf("%s\n", name3);
system("pause");
return 0;
}
? ? ?
C语言字符串的输入输出
#include <stdio.h>
#include <Windows.h>
int main(void) {
char language[32];
char year[32];
printf("修炼的什么语言? \n");
scanf_s("%s", language, 32);
rewind(stdin);
printf("修炼几年了? \n");
gets_s(year, 32);
printf("你修炼 %s 语言已经 %s 了 !\n", language, year);
system("pause");
return 0;
}
|