Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <limits.h>
- void print_numbers(char *input);
- int main(int argc, char *argv[])
- {
- if (argc == 1)
- {
- char buf[LINE_MAX+1];
- while (fgets(buf, LINE_MAX, stdin))
- print_numbers(buf);
- }
- else
- {
- for (int k = 1; k < argc; k++)
- {
- char *input = argv[k];
- print_numbers(input);
- }
- }
- return 0;
- }
- void print_numbers(char *input)
- {
- int len = strlen(input);
- char *buf = malloc((len * sizeof(char)) + 1);
- if (buf)
- {
- int j = 0;
- for (int i = 0; i < len; i++)
- {
- char c = input[i];
- if (c >= 48 && c <= 57)
- buf[j++] = c;
- }
- buf[j] = '\0';
- printf("%s", buf);
- free(buf);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement