- 1 year ago
getting the (star-symbol) as input in a c program
To get the star symbol (*) as input in a C program, you can use the scanf
function with the %c
format specifier. Here's an example:
c#include <stdio.h>
int main() {
char symbol;
printf("Enter the star symbol (*): ");
scanf(" %c", &symbol); // Notice the space before %c to skip leading whitespace
printf("You entered: %c\n", symbol);
return 0;
}
In this example, the scanf
function reads a single character from the user, including whitespace characters. The space before %c
in the format string is used to skip any leading whitespace before reading the character.
When executing the program, it will prompt the user to enter the star symbol. After the user inputs the symbol and presses Enter, the program will display the entered symbol using printf
.
Note that the scanf
function may have limitations when reading certain special characters or characters with special meanings in the format string. In such cases, you may need to use alternative approaches or techniques to read the desired input.