cprimer_study/c04_string/praise2.c
2023-12-05 20:18:13 +08:00

27 lines
958 B
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* praise2.c */
// 如果编译器不识别%zd尝试换成%u或%lu
// 在gcc version 10.2.1 20210110 (Debian 10.2.1-6)环境中
// %zd统一换成%d得到的结果是一致的
#include <stdio.h>
#include <string.h>
#define PRAISE "You are an extraordinary being."
int main(void)
{
char name[40];
printf("What's your name? ");
scanf("%s", name);
printf("\n");
printf("Hello, %s. %s\n", name, PRAISE);
printf("Your name of %d letters occupies %d memory cells.\n", strlen(name), sizeof(name));
printf("The phrase of praise has %d letters", strlen(PRAISE));
printf("and occupies %d memory cells.\n", sizeof(PRAISE));
printf("\n");
printf("Hello, %s. %s\n", name, PRAISE);
printf("Your name of %zd letters occupies %zd memory cells.\n", strlen(name), sizeof(name));
printf("The phrase of praise has %zd letters", strlen(PRAISE));
printf("and occupies %zd memory cells.\n", sizeof(PRAISE));
return 0;
}