字符与字符串

## Scanf

     -- scanf()会在遇到第一个空白字符空格、制表符或者换行符处停止读取。

    #include<stdio.h>

    #define PRAISE "What a super marvelous name!"

int main(void)
{
char name[40];
printf("What's your name?\n");
scanf("%s",name);
printf("Hello,%s. %s\n",name,PRAISE);
return 0;
}

Harray Buddles

##字符串和字符

    1.单引号字符,双引号字符串

    2.字符串存储\0结尾数组

##strlen()&sizeof()

    strlen():字符占用的实际长度

    sizeof():变量存储长度(包含\0)


#include<stdio.h>
#include<string.h>
#define PRAISE "What a super marvelous name!"
int main(void)
{
char name[40];
printf("What's your name?\n");
scanf("%s",name);
printf("Hello %s . %s\n",name,PRAISE);
printf("Your name of %d letters occupies %d memory cells.\n",strlen(name),sizeof name);
pirntf("The phrase of praise has %d letters",strlen(PRAISE));
printf("and occupies %d memory cells.\n",sizeof PRAISE);
return 0;
}

## 宏与常量

    常量:变量转常量,变成只读

    宏:

#include<stdio.h>
#include<string.h>
#define PRAISE "What a super marvelous name!"
int main(void)
{
const int MONTH=12;
char name[40];
printf("What's your name?\n");
scanf("%s",name);
printf("Hello %s . %s\n",name,PRAISE);
printf("Your name of %d letters occupies %d memory cells.\n",strlen(name),sizeof name);
pirntf("The phrase of praise has %d letters",strlen(PRAISE));
printf("and occupies %d memory cells.\n",sizeof PRAISE);
return 0;
}

 

 

 

 

 

 

      

 

posted @ 2021-03-09 11:37  菲阳公社  阅读(62)  评论(0)    收藏  举报