How To Have Input In C For String?

Use `scanf(“%s”, str);`

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

Declare the string as `char str[100];`

For a single word input, use `scanf(“%99s”, str);`

For full-line input with spaces, use `fgets(str, 100, stdin);`

Remove the trailing newline after `fgets` if needed

Avoid using `gets(str);`

Suggested for You

Trending Today