Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define LEN 10
- char * getnchar(char * str, int n);
- int main(void)
- {
- char input[LEN];//prepare the memory block when main() is executing.
- char *chk;
- chk = getnchar(input, LEN - 1);
- //this if branch has no sense in terms of usage except the first console input is EOF
- //I hasn't caught any implementation in the corresponding function
- if (chk == NULL)
- puts("Input failed.");
- else
- puts(input);
- puts("Done.\n");
- return 0;
- }
- char * getnchar(char * str, int n)
- {
- int i;
- int ch;
- for (i = 0; i < n; i++)
- {
- ch = getchar();
- if (ch != EOF)
- str[i] = ch;
- else
- break;
- }
- //????????? logic has no sense to me.
- if (ch == EOF)
- return NULL;
- else
- {
- str[i] = '\0';
- return str;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement