Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- size_t getlines(char* s, size_t lim) {
- size_t n = 0;
- char c;
- while(n < lim && (c = getchar()) != EOF && c != '\n') {
- *s = c;
- n++;
- s++;
- }
- if (c == '\n') *s = '\n';
- return n;
- }
- int main() {
- char* str = malloc(sizeof(char) * 15);
- getlines(str, 15);
- printf("%s", str);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement