#include <stdlib.h>
#include <stdio.h>
int main()
{
int size=1000, i=0;
FILE *fp;
char *buffer, *temp, *token;
int c;
fp = fopen("test.txt", "r");
if(fp == NULL) {
printf("Couldn't open file!\n");
return -1;
}
buffer = malloc(size);
if(buffer == NULL) {
printf("malloc failed\n");
return -1;
}
while((fgets(buffer+i, 1000, fp)) != NULL) {
size += 1000;
i+=999;
temp = realloc(buffer, size);
if(temp == NULL) {
printf("realloc failed!\n");
return -1;
}
buffer = temp;
}
temp = malloc(size);
strncpy(temp, buffer, size);
token = strtok(temp, " ");
c = strtol(token, NULL, 2);
putchar(c);
while((token=strtok(NULL, " ")) != NULL) {
c = strtol(token, NULL, 2);
putchar(c);
fflush(stdout);
}
putchar('\n');
fclose(fp);
free(buffer);
free(temp);
return 0;
}