![]() ![]() | strings/string-input-fgets.c - Et program der indlæser en line af tekst med fgets - sikkert. | Lektion 10 - slide 48 : 51 Program 2 |
// Source file: string-input-fgets.c #include <stdio.h> #include <string.h> #define LIMIT 20 int main(void) { char input[LIMIT]; do { printf("Enter a string: "); fgets(input, LIMIT, stdin); // Safe. Reads newline as well. Terminates with '\0' printf("You entered \"%s\"\n", input); } while (strncmp(input, "exit", 4)); return 0; }