Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main()
- {
- FILE *name1;
- char **text=NULL;
- int i,j,y;
- int number = 0;
- int count=0;
- int temp_realloc;
- int control_var = 5;
- text = (int*) malloc(sizeof(int*)*control_var);
- for(i=0; i < control_var ;i++)
- {
- text[i] = (char *) malloc(50);
- }
- name1 = fopen("C:\\Users\\Iceekk\\Desktop\\traa\\versionTOMOV.bin", "rb");
- if(name1 == NULL)
- {
- printf("error with opening file for read..");
- return -1;
- }
- while(1)
- {
- if(fread(&number, sizeof(int) , 1 , name1) != 1)
- {
- printf("\nSuccesfull Reading of .BIN FILE\n");
- break;
- }
- if(fread(text[count],number,1,name1) != 1)
- {
- printf("\nError while reading string! \n");
- exit(-1);
- break;
- }
- for (j=0; j<number ; j++ )
- {
- printf("%c", text[count][j]);
- }
- printf("\n");
- // count++;
- if((count+1) >= control_var) // zavisi ot count !!!
- {
- temp_realloc = count;
- control_var *= 2;
- text =(int *) realloc(text, sizeof(int*) *control_var);
- for (y = temp_realloc ; y < control_var ; y++)
- {
- text[y] = (char *) malloc(30);
- }
- }
- count++;
- }
- fclose(name1);
- for (i=0;i<control_var;i++)
- {
- free(text[i]);
- }
- free(text);
- text=NULL;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement