Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. List * readFileToList() {
  2.     List  * list = List_new();
  3.     char * buffer =  malloc(sizeof(char)*100) ;
  4.     char * stringBuffer =  malloc(sizeof(char)*100) ;
  5.     const char * input = readFileToBuffer("data.txt", buffer, 10000);
  6.     while(input != '\0'){
  7.     if (isdigit(*input))
  8.         {
  9.             while (isdigit(*input))
  10.             {
  11.                 StringBuffer_appendChar(stringBuffer, *input);
  12.                 input++;
  13.             }
  14.             int* i = malloc(sizeof(int));
  15.             char * buf = StringBuffer_toNewString(stringBuffer);
  16.             *i = atoi(buf);
  17.             free(buf);
  18.             List_add(list, i);
  19.             StringBuffer_clear(stringBuffer);
  20.         }
  21.      input++;
  22.     }
  23.     return list;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement