我是编码的初学者,并试图完成我的作业.
虽然我已经解决了我的问题,但是在这样做时我偶然发现了\ t的意外行为.我得到单个\ t的不同标签长度.这是我的代码:
#include<stdio.h>
int calculate_intpart_qutent(int dividend, int diviser);
int main()
{
int a;
int b;
int choice;
do
{
printf("Enter the Dividend (a) :\t");
scanf("%d", &a);
printf("\nEnter the Divisor (b) :\t");
scanf("%d", &b);
printf("\n\nThe quotient is:\t%d", calculate_qutent(a, b));
printf("\n\nDo you want to try again?(Y\\N):\t");
choice = getchar();
if (choice == '\n') choice = getchar();
printf("\n\n\n");
} while (choice=='y'|| choice=='Y');
}
int calculate_intpart_qutent(int dividend, int diviser)
{
return (dividend/diviser);
}
Run Code Online (Sandbox Code Playgroud)
这是我的输出:
由于我在两个第一个printf语句中都使用了单选项卡,为什么我在输出屏幕上获得不同的选项卡长度?我在这里做错了什么?
在你投票并埋葬这个问题之前,请考虑我是C的初学者.任何帮助都感激不尽.
我正在使用Visual Studio 2017 RC.
由于我在两个第一个printf语句中都使用了单选项卡,为什么我在输出屏幕上获得不同的选项卡长度?
使用选项卡不保证打印空间的数量.
如果你想要固定的长度printf然后尝试相似的东西%-30s.它保证30个空间用于打印的字符串-左对齐.
printf("%-30s", "Enter the Dividend (a) :");
scanf("%d", &a);
printf("\n%-30s", "Enter the Divisor (b) :");
scanf("%d", &b);
Run Code Online (Sandbox Code Playgroud)