SHOW:
|
|
- or go back to the newest paste.
| 1 | List * readFileToList() {
| |
| 2 | List * list = List_new(); | |
| 3 | char * buffer = malloc(sizeof(char)*100) ; | |
| 4 | - | char * stringBuffer = malloc(sizeof(char)*100) ; |
| 4 | + | char * stringBuffer = StringBuffer_new(); |
| 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); |
| 15 | + | char * buf = StringBuffer_toString(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 | } |