I am writing a basic function in C on Visual Studio Code and while taking input from the user using scanf
, the string in scanf
is not visible on the command line. It just shows a blank space. I wanted to let the user know that they are supposed to enter an input.
#include<stdio.h> // header files
void main()
{
printf("\n Please select the number of Players:\n");
printf(" 1. Single Player - V/S AI (in development)\n");
printf(" 2. Two Player Game - V/S Friend \n");
int no_of_players;
scanf("Enter %i",&no_of_players);
printf("\n You selected, %i", no_of_players);
}
This is the compiler, if ($?) { gcc tic_tac_toe.c -o tic_tac_toe } ; if ($?) { .\tic_tac_toe }
CodePudding user response:
The string in scanf
is not a prompt. It is a format string specifying what the user should enter. In this case, it says that the string "Enter " must be typed in followed by an integer.
What you want instead is to use printf
to print any string you want displayed and have scanf
contain just the format specifier.
printf("Enter: ");
scanf("%i",&no_of_players);