首页 > 其他 > 详细

字符与字符串

时间:2021-03-09 14:23:31      阅读:16      评论:0      收藏:0      [点我收藏+]

## 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;
}

 

 

 

 

 

 

      

 

字符与字符串

原文:https://www.cnblogs.com/alexbob/p/14497926.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!