-
再次运行程序,输入David mk结果如下图
由于使用%s读取用户输入,scanf读取到David mk中间的空格处停止,所以name中只接收到了David, 空格停留在输入中,接下来%f也不会读取空格,所以weight没得到数据,执行结果和将scanf("%f", &weight);注释掉的结果是相同的 -
a. He sold the painting for $234.50.
b. Hi!
c. His Hamlet was funny without being vulgar.
has 42 characters.d. Is 1.20e+003 the same as 1201.00?
-
答案1:#define Q ““His Hamlet was funny without being vulgar.”” 答案二,在打印字符串Q的前后加上转换说明/":
printf("\"%s\"\n has %d characters. \n", Q, strlen(Q));
-
修改后的程序如下:
#include <stdio.h>
#define B "booboo"
#define X 10
int main(void)
{
int age, xp ;
char name[40];
printf("Please enter your first name. \n");
scanf("%s", name);
printf("All right, %s, what's your age?\n", name);
scanf("%d", &age);
xp = age + X;
printf("That's a %s! You must be at least %d.\n", B, xp);
return 0;
}
printf("This copy of \"%s\" sells for $%.2f.\n", BOOK, cost);
printf("That is %.0f%% of list.", percent);
-
a. %d b. %4X c. %10.3f d. %12.2e e. %-30s
- a. %15lu
b. %#4x
c. %-12.2E
d. %+10.3f
e. %8.8s -
b. %*oa. %6.4d
c. %2c
d. %+.2f
e. %-7.5s -
b.a. `int a; scanf("%d", &a);`
double d; scanf("%e", &d);
c.char array[40]; scanf("%s", array);
d.char array1[40]; int a1; scanf("%s %d", array1, &a1);
e.char array2[40]; int a2; scanf("%*s %d", &a2);
- what is whitespace? space tablet enter 空格 制表符 回车符,补充:C语言使用空白分隔几号,scanf使用空白分隔连续的输入项
- %只是修饰符,修改后的语句为,
printf("The double type is %zd bytes..\n", sizeof(double));
- 当然不行了
编译时会报错,如下图所示: