這是c中的一個簡單程序。它需要兩個整數並添加它們。在這段代碼中,我想用新行更新上一行而不是新行,任何主體都可以幫助我解決這個問題。更新上一行代替打印新行
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b;
printf("Enter two integer to add\r");
scanf("%d%d",&a,&b);
a=a+b;
printf("Your value is -- %d",a);
return 0;
}
我使用\ r而不是\ n,將光標移回到開始位置。我從程序控制臺輸入數據,從頭開始寫。但是下一行「Your value is ..」打印爲新行,我想刪除第一行然後輸入值並打印下一行「Your value ..」。我怎麼做?請幫我
簡答:你不能(很容易)。長的答案:你想要的不是標準C語言或運行時的一部分。像[ncurses](https://en.wikipedia.org/wiki/Ncurses)是另一種選擇,但坦率地說,就像用大錘開着圖釘。 – WhozCraig