Top "Scanf" questions

Questions related to the scanf() family of functions in the C runtime library, which read and convert formatted data.

Why does scanf ask twice for input when there's a newline at the end of the format string?

#include <stdio.h> #include <stdlib.h> #include <string.h> char *method1(void) { static char …

c scanf
How can I prevent scanf() to wait forever for an input character?

I want to fulfill the following things in a console application: If user inputs a character, the application will do …

c scanf
Scanf skips every other while loop in C

I'm trying to develop a simple text-based hangman game, and the main game loop starts with a prompt to enter …

c gcc scanf
How to use sscanf in loops?

Is there a good way to loop over a string with sscanf? Let's say I have a string that looks …

c string scanf
Doesn't %[] or %[^] specifier in scanf(),sscanf() or fscanf() store the input in null-terminated character array?

Here's what the Beez C guide (LINK) tells about the %[] format specifier: It allows you to specify a set of …

c string scanf format-specifiers character-arrays
Clearest way to read and print .txt file lines in C

There are a bunch of ways describing how to use various methods to print out lines of a text file …

c file-io scanf printf file-read
fgets doesn't work after scanf

#include <stdio.h> #include <string.h> #include <ctype.h> void delspace(char *str); int …

c scanf fgets
Difference between %u and %d in scanf()

In C++, if I read an integer from a string, it seems it does not really matter whether I use …

c++ scanf cstdio
Get number of characters read by sscanf?

I'm parsing a string (a char*) and I'm using sscanf to parse numbers from the string into doubles, like so: // …

c string-parsing scanf
whitespace in the format string (scanf)

Consider the following code: #include<stdio.h> int main() { int i=3, j=4; scanf("%d c %d",&i,&…

c input whitespace scanf stdio