While you are giving like this, It will not ignore the white spaces.

scanf("%c",&ch);

When you are giving the input to the first scanf then you will give the enter('\n'). It is one character so it will take that as input to the second scanf. So second input will not get input from the user.

scanf(" %c",&ch);

If you give like this, then it will ignore that white space character, then it will ask for the input from the user.

Answer from Karthikeyan.R.S on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_user_input.php
C User Input
Read input typed by the user in C with the scanf() function.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ how-to-input-or-read-a-character-word-and-a-sentence-from-user-in-c
How to input or read a Character, Word and a Sentence from user in C? - GeeksforGeeks
July 23, 2025 - Problem Statement#2: Write a C program to read words as input from the user. ... First, initialize the char array of size ( greater than are equal to the length of word). Then, use %s format specifier to take the string using the scanf() function.
Discussions

How to input a character in C
does it work if you input 12M instead of 12M? More on reddit.com
๐ŸŒ r/learnprogramming
12
2
March 31, 2022
c programming, questions regarding getting user input functions
Ideally you would tell us what input you used, I assume it looks something like this: 75.2 My beautiful name Newline characters that are used to confirm input however are also characters, so you can say that the input looks like this (replaced actual newline character with '\n'): 75.2\nMy beautiful name\n The thing is that you also must deal with those characters, depending on what reading method you use. Lets use this input for your program and see what happens. First you read a float, so from the input above, 75.2 is read and stored and you are left with \nMy beautiful name\n Notice that you still have a newline character at the beginning of the input after you read the float. The second read uses fgets() function, which only reads a line until next newline character (until '\n'), but since you did not clear the newline character which was used to confirm the first input, fgets() only reads the newline character and nothing else, thats how it is meant to read. So you read newline character into variable "name" and this was left on the input: My beautiful name\n If you did another fgets(), you would probably get the correct result, if you inputted both inputs at the same time like this: 75.2 My beautiful name It would probably also work, though you would get an extra space at the beginning of name variable. To sum it up, you had extra newline character after first input, which was read by fgets() as a line, making it appear it did not happen. You must somehow discard the newline character after first scanf, then use fgets. More on reddit.com
๐ŸŒ r/cprogramming
4
5
January 2, 2023
Still confused in taking Input in C
Have you read https://sekrit.de/webdocs/c/beginners-guide-away-from-scanf.html ? More on reddit.com
๐ŸŒ r/C_Programming
30
30
February 9, 2024
How to read from user input without the \n ?
Maybe try with bufio.NewScanner(os.Stdin) More on reddit.com
๐ŸŒ r/golang
8
0
March 12, 2017
๐ŸŒ
Programiz
programiz.com โ€บ c-programming โ€บ c-input-output
C Input/Output: printf() and scanf()
April 27, 2022 - #include <stdio.h> int main() { char chr = 'a'; printf("character = %c", chr); return 0; } ... To print char, we use %c format specifier. In C programming, scanf() is one of the commonly used function to take input from the user.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ getchar() function in c
Getchar() function in C - Scaler Topics
April 16, 2024 - The getchar in C is a non-standard function whose definition is already defined in the stdio.h header file and it is used to take the input of a single character(unsigned char) from the standard input(stdin).
๐ŸŒ
YouTube
youtube.com โ€บ logic lambda
Getting Input One Character at a Time in C - YouTube
0:33 - Reading input one character at a time (getchar)3:00 - Using getc & putc to read & write one character at a time
Published: January 7, 2022
Views: 1K
๐ŸŒ
CodeChef
codechef.com โ€บ blogs โ€บ c-user-input
How to accept User Inputs in C (Examples and Practice)
August 6, 2024 - Learn how to take user input in C with this beginner-friendly guide. Discover string and integer inputs, handling multiple inputs, and practical examples to enhance your C programming skills
Find elsewhere
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ strings input and output functions in c
Strings Input and Output functions in C
November 16, 2023 - Let us look at an example to understand the working of scanf() in C. ... The scanf() function is probably the easiest way to string input in C. We just need the access specifier %s and the pointer to the variable where we want the string to be stored, and it becomes very easy to input the string ...
๐ŸŒ
EasyExamNotes
easyexamnotes.com โ€บ c-character-input
C Character input โ€“ EasyExamNotes.com
The scanf() function with the %c format specifier is used to read a character from the userโ€™s input. The & operator is used to pass the memory address of the input variable so that the value can be stored there. The printf() function displays the message โ€œYou entered: โ€ followed by the ...
๐ŸŒ
YouTube
youtube.com โ€บ watch
C user input โŒจ๏ธ - YouTube
C how to accept user input scanf fgets tutorial example explained#C #user #input char name[25]; //bytes int age; printf("\nWhat's your name?");
Published: August 24, 2021
๐ŸŒ
CodeScracker
codescracker.com โ€บ c โ€บ program โ€บ c-program-receive-input.htm
C program to get input from the user
Simply use the format specifier and the variable that contains the value. Whereas, while scanning the input, the "address of" operator is used to put or store the entered value at the address of a given variable, say num. Now let's create another program that receives character-type input data ...
๐ŸŒ
Quora
quora.com โ€บ How-can-you-make-a-user-input-characters-in-C-C-programming
How to make a user input characters in C/C++ programming - Quora
Answer (1 of 2): No one can โ€˜makeโ€™ anyone do anything. You can issue orders, give them suggestions, coerce or threaten them. You can block them from doing anything else in your program until they enter the required characters, but you canโ€™t make them do anything.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ how to input a character in c
r/learnprogramming on Reddit: How to input a character in C
March 31, 2022 -

Can someone explain how can i input a single character like for example in the below code on line 10 i tried to input a character using scanf() but it doesn't seem to work. It doesn't show any errors but moves on without waiting for an input.

/* Programm to Find out the maximum Range of an antena */

#include <stdio.h>

int main(void) {

float height;

int range;

char matric;

printf("How high is the Antena\n");

scanf("%f", &height);

printf("What Unit is it?\nM - for Meter\nK- for Km");

scanf("%c", &matric);

if(matric =='M'){

range = sqrt(12800000*height);

printf("Range is %d M",range);

}

else{

range = sqrt(12800*height);

printf("Range is %d KM",range);

}

return 0;

}

if i write %s instead of %c in line 10 it works. can someone please help

๐ŸŒ
IncludeHelp
includehelp.com โ€บ c-programs โ€บ input-individual-characters-using-scanf.aspx
Input individual characters using scanf() in C
Enter 3 character values: a b c x= 'a' y= ' ' z= 'b' Here, x contains 'a', y contains ' ' (space) and z contains 'b'. #include <stdio.h> int main(void) { char x; char y; char z; //input printf("Enter 3 character values: "); scanf ("%c%*c%c%*c%c", &x, &y, &z); //print printf("x= \'%c\' \n", x); printf("y= \'%c\' \n", y); printf("z= \'%c\' \n", z); return 0; }
๐ŸŒ
Medium
medium.com โ€บ @arashtad โ€บ user-input-scanf-and-getchar-in-c-12710a7eca89
User Input scanf and getchar in C | by Arashtad | Medium
August 15, 2025 - Here, %d tells scanf() to read an integer, and &age passes the address of the variable to store the input. getchar() reads a single character from the user. Unlike scanf(), it is more low-level and does not require format specifiers.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ cprogramming โ€บ c_input_output.htm
Input and Output Functions in C
The scanf() function reads the input from the standard input stream stdin and scans that input according to the format provided โˆ’ ... The printf() function writes the output to the standard output stream stdout and produces the output according ...
๐ŸŒ
Medium
medium.com โ€บ @sorowarmahabub1709vip โ€บ problem-in-character-input-after-an-integer-input-in-c-programming-783d2796a40d
Problem in Character input after an integer input in C programming | by Md Sorowar Mahabub Rabby (Sorowar Mahabub) | Medium
April 1, 2023 - ... int num; char ch; scanf("%d", &num); scanf(" %c", &ch); printf("num = %d\n", num); printf("ch = %c\n", ch); With this change, the scanf call for the char variable ch will consume the newline character left in the input buffer, and then read ...
๐ŸŒ
Log2Base2
log2base2.com โ€บ C โ€บ string โ€บ get-string-input-from-user-in-c.html
Get string input from user in c
Using %s format specifier in scanf, we can get string input from the user. While getting string input, no need to give the & operator in scanf as the string name itself a base address of the string.This tutorial explains about how to get the string input from the user.
๐ŸŒ
ProCoding
procoding.org โ€บ c-program-to-take-string-as-an-input
C Program to take string as an input | ProCoding
June 21, 2024 - Each method of taking string input in C has its strengths and weaknesses. For simple, single-word input, scanf can be quite effective. However, for multi-word strings, fgets provides a safer and more robust option compared to the deprecated gets.
๐ŸŒ
DEV Community
dev.to โ€บ mujahida_joynab_64c7407d8 โ€บ how-to-take-string-input-in-c-29ba
How to take string input in c - DEV Community
October 25, 2024 - Method 01: To take input string of a word we use char str[30] ; scanf("%s",str) ; printf("%s",str)...