1234567891011121314
char *getsn(char *buffer, int size) { char c; char *ptr = buffer; while(size > 1 && ptr != NULL && (c = getchar()) != '\n') { if(c == EOF) { ptr = NULL; } else { *ptr++ = c; --size; } } if(ptr != NULL) { *ptr = 0; ptr = buffer; } return ptr;}