- 用双引号将其打印
- 将其打印在20个字符宽的字段中,整个字段用引号括起,名称在字段的右端。
- 在20字符宽的字段的左端打印它,整个字段用引号括起来。
- 将其打印在比名称宽三个字符的字段中。
#include <stdio.h>
#include <string.h>
int main(void)
{
char name[20];/*from w w w.j ava 2 s.c o m*/
int name_length;
printf("Enter your first name: ");
scanf("%s", name);
name_length = strlen(name);
printf("/"%s/"/n", name); // a. enclosed in double quotes
printf("/"%20s/"/n", name); // b. double quotes, 20 char wide, right-justified
printf("/"%-20s/"/n", name); // c. double quotes, 20 char wide, left-justified
printf("/"%*s/"/n", name_length + 3, name); // d. double quotes, 3 char wider than name
return 0;
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/266406.html