...
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <stdio.h> #include <string.h> #define BUFFER_SIZE 128 void func(void) { char buf[BUFSIZBUFFER_SIZE]; if (fgets(buf, sizeof(buf), stdin) == NULL) { /* Handle error */ } buf[strlen(buf) - 1] = '\0'; /* discard newline */ } |
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <stdio.h> #include <string.h> #define BUFFER_SIZE 128 void func(void) { char buf[BUFSIZBUFFER_SIZE]; char *p; if (fgets(buf, sizeof(buf), stdin)) { buf[BUFFER_SIZE - 1] = '\0'; p = strchr(buf, '\n'); if (p) { *p = '\0'; /* discard newline */ } } else { /* Handle error */ } } |
...