Please take a look at the codes (both correct and incorrect) first-
incorrect code-
char* buffer = malloc(*counter);
char* ch = malloc(sizeof(char));
for (*ch=fgetc(file);*c != EOF;*ch=fgetc(file))
{
buffer[*i] = *ch;
*i = *i + 1;
}
*content = buffer;
Then I changed
char* ch = malloc(sizeof(char));
to-
int* ch = malloc(sizeof(int));
And everything worked fine (of course only the static data, but that is not a point i want to make)
and then to-
int* ch = malloc(sizeof(char));
and still everything alright.
- What difference it makes to assign int* or char* to "ch".
- I specified int* ch and size of an Int in malloc (in first correction) but my buffer elements are still of type char and of size of a char. Then how the code still works?