Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define MAXLINE 1000
- int getchars(char *s, int max);
- int main(void)
- {
- char *s;
- printf("enter string s:\n");
- while (getchars(s, MAXLINE) == 0)
- ;
- printf("%s\n", s);
- }
- int getchars(char *s, int max)
- {
- int i, l;
- char c;
- for (i = 0, l = 0; ((c = getchar()) != EOF) && c != '\n'; i++) {
- if (i<max-1) {
- *s++ = c;
- ++l;
- }
- }
- *s = '\0';
- return l;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement