How To Have Input In C?

Use `scanf()` for formatted input

Use `getchar()` for reading a single character

Use `fgets()` for reading a line of text

Use `gets()` is unsafe and should not be used

Use `printf()` to prompt the user before input

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

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

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

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

Use `stdin` for standard input

Use `&` to pass variable addresses to `scanf()`

Use `EOF` to detect end of input

Use `sscanf()` to read input from a string

Use `fscanf()` to read input from a file stream

Suggested for You

Trending Today