How to Get Input in C?

Use `scanf()` for formatted input

Use `getchar()` to read a single character

Use `fgets()` to read a line of text

Use `gets()` only if required by legacy code

Use `fread()` for binary input

Use `fgetc()` to read one character from a file or input stream

Use `scanf(“%d”, &x);` for integers

Use `scanf(“%f”, &x);` for floating-point values

Use `scanf(“%c”, &ch);` for a character

Use `fgets(str, size, stdin);` for strings

Use `scanf(“%s”, str);` for a word without spaces

Suggested for You

Trending Today