觉得有用的看官评论下,评论有用或者1就行了哈,给作者动力啊!
c
#include <stdio.h>
#include <string.h>
#define PRAISE "You are an extraordinary being."//这里有31个字符,加上空格和"."
int main(void){
char name[40];
printf("please input your name!");
scanf("%s", name);//scanf函数,在输入的字符串中如果遇到空格、制表符和换行符就会自动停止,如果输入Bard James,就只会读取Bard,后面的James读取不了
printf("Hello,%s,welcome to my home %s\n", name, PRAISE);//这里会显示Bard,welcome to my home You are an extraordinary being
printf("Yor name of %zd letters occupies %zd memory cells \n", strlen(name),sizeof name);//Yor name of 4 letters occupies 40 memory cells
printf("The phrase of praise has %zd letters ", strlen(PRAISE));//这里是31
printf("and occupies %zd memory cells.\n",sizeof PRAISE);// 这里sizeof函数,要算末尾的空字符\0 。而strlen函数是不包含\0的
return 0;
}
结果如下
