Advertisement
Guest User

rk3

a guest
Dec 11th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define BUFLEN 128
  5.  
  6. struct list{
  7.     char *p_str;
  8.     int i;
  9.     struct list *next;
  10. }*start=NULL;
  11. struct list *prev;
  12.  
  13. FILE *fp;
  14.  
  15. void add(char *stroka)
  16. {
  17.     struct list *temp;
  18.     if (check_number(stroka))
  19.     {
  20.         if((temp = (struct list*)malloc(sizeof(struct list))) == NULL)
  21.         {
  22.             printf("Memory overflow");
  23.             exit(4);
  24.         }
  25.         if (start == NULL) start=temp;
  26.         else prev->next=temp;
  27.         temp->next=NULL;
  28.         temp->p_str=stroka;
  29.         temp->i=1;
  30.         prev=temp;
  31.     }
  32. }
  33.  
  34. int main(int argc, char **argv)
  35. {
  36.     int i, end = 0;
  37.     if(argc == 1)
  38.         {
  39.             printf("Enter the directory of file");
  40.             exit(1);
  41.     }
  42.     if((fp=fopen(argv[1], "r")) == NULL)
  43.     {
  44.         printf("Open failed");
  45.         exit(2);
  46.     }
  47.     do
  48.     {
  49.         c = fgetc(fp);
  50.         if (c >= '0' && c <= '9')
  51.             {
  52.                 buf[i] = c;
  53.                 i++;
  54.             }
  55.             else
  56.             {
  57.                 buf[i] = '\0';
  58.                 if((end = i))
  59.                 {
  60.                     if((p = (char*)malloc(sizeof(char)*(end+1))) == NULL)
  61.                     {
  62.                         printf("Memory overflow");
  63.                         exit(4);
  64.                     }
  65.                 strcpy(p, buf);
  66.                     add(p);
  67.                     }
  68.         i = 0;
  69.             }
  70.     } while (c != EOF);
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement