Command-Line Input with fgets in C
The fgets function allows you to read input from the user, including spaces, until a specified delimiter or newline character is encountered.
#include <stdio.h>
int main() {
char input[100];
printf("Enter a line of text: ");
fgets(input, sizeof(input), stdin);
printf("Input: %s", input);
return 0;
}
In this example, the program uses fgets to read a line of text from the user. The input is stored in the input character array, and then it is printed on the console.
No comments:
Post a Comment