// Demo program for getline() #define _GNU_SOURCE #include #include #include int main() { printf("What’s your name? "); fflush(stdout); char *name = 0; size_t n; ssize_t m = getline(&name, &n, stdin); for (ssize_t i = 0; i != m; i++) if (name[i] == '\n') name[i] = '\0'; printf("Hi, %s! Nice to meet you!\nYour full name is ‘", name); fflush(stdout); write(1, name, m-1); // This prints the name even if it had embedded nulls. printf("’.\n"); free(name); return 0; }