Advertisement
agudelo1200

_getline.c

Apr 10th, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #ifndef SHELL
  2. #define SHELL
  3. #define MAXLINE 100 /* maximum input line length */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7. #include <string.h>
  8. #include <sys/wait.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11.  
  12. extern char **environ;
  13. int _getline(char line[], int maxline);
  14. void exe(char str[], int size);
  15.  
  16. #endif
  17.  
  18. /**
  19.  * _getline - read a line
  20.  * @s: storage line into s
  21.  * @lim: MAXLINE
  22.  * Return: length
  23.  */
  24. int _getline(char s[], int lim)
  25. {
  26.     int c, i;
  27.  
  28.     for (i = 0; i < (lim - 1) && (c = getchar()) != EOF; ++i)
  29.     {
  30.         if (c == '\n')
  31.         {
  32.             s[i] = 0;
  33.             return (i);
  34.         }
  35.         s[i] = c;
  36.     }
  37.     return (i);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement