c - 有没有办法在 C 中制作这样的节日树?
问题描述
我想知道你是否可以在 C 上将这些单词重新排列成这种格式
Jojo|Jojo
is|is
the|the
Best|Best
Intheworld|Intheworld
这是我输入的代码,但它似乎不起作用:
char a[50],b[50],c[50],d[50];
gets(a);
gets(b);
gets(c);
gets(d);
//tried to putt it into the middle with this string
a[strcspn(a, "\n")] = 0;
b[strcspn(b, "\n")] = 0;
c[strcspn(c, "\n")] = 0;
d[strcspn(d, "\n")] = 0;
//this is how i print it
printf(" %s|%s\n",a,a);
printf(" %s|%s\n",b,b);
printf(" %s|%s\n",c,c);
printf(" %s|%s\n",d,d);
解决方案
不要在第一组字符串之前放置空格,而是在打印的第一个字符串上使用字段宽度。这将使给定长度的字段中的字符串右对齐:
printf("%40s|%s\n",a,a);
printf("%40s|%s\n",b,b);
printf("%40s|%s\n",c,c);
printf("%40s|%s\n",d,d);
推荐阅读
- actions-on-google - Dialogflow 未触发所需参数的提示
- regex - Notepad++ 正则表达式重新排序字符串
- sql - 提取过去 7 天的数据(不能使用 current_date 函数)
- javascript - 使用 javascript 在 MVC 视图的页面加载上设置页面滚动位置
- gitlab-ci - 跨越多个阶段的 CI 作业
- php - 记住递归函数值
- javascript - 查找 Aws S3 存储桶位置
- java - Intellij 不正确加载项目
- javascript - ForEach 百里香 javascript
- python-asyncio - 为什么 loop.run_forever() 会锁定我的主线程?