Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define BUFLEN 128
- struct list{
- char *p_str;
- int i;
- struct list *next;
- }*start=NULL;
- struct list *prev;
- FILE *fp;
- void add(char *stroka)
- {
- struct list *temp;
- if (check_number(stroka))
- {
- if((temp = (struct list*)malloc(sizeof(struct list))) == NULL)
- {
- printf("Memory overflow");
- exit(4);
- }
- if (start == NULL) start=temp;
- else prev->next=temp;
- temp->next=NULL;
- temp->p_str=stroka;
- temp->i=1;
- prev=temp;
- }
- }
- int main(int argc, char **argv)
- {
- int i, end = 0;
- if(argc == 1)
- {
- printf("Enter the directory of file");
- exit(1);
- }
- if((fp=fopen(argv[1], "r")) == NULL)
- {
- printf("Open failed");
- exit(2);
- }
- do
- {
- c = fgetc(fp);
- if (c >= '0' && c <= '9')
- {
- buf[i] = c;
- i++;
- }
- else
- {
- buf[i] = '\0';
- if((end = i))
- {
- if((p = (char*)malloc(sizeof(char)*(end+1))) == NULL)
- {
- printf("Memory overflow");
- exit(4);
- }
- strcpy(p, buf);
- add(p);
- }
- i = 0;
- }
- } while (c != EOF);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement