I want the output of the following code as
-|-2-|-
(When i input the value of key as 2). I know \b just move the cursor to 1 space back but why it isn't able to move one space back after a newline is used to input the value of key. Is it possible to use the escape character \b after a newline character has been used.
#include<stdio.h>
#include<conio.h>
int main()
{
int key;
printf("Enter value of key: )"
printf("-|-");
scanf("%d",&key);
printf("\b-|-");
return 0;
}
Here is a simple solution :
#include<stdio.h>
int main()
{
int key;
char output[8] = {'\0'};
printf("Enter value of key: )";
scanf("%d",&key);
sprintf(output,"-|-%d-|-",key);
printf("%s\r\n",output);
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With