Need some reassurance
Not wondering about syntax or semantics btw.
Lets say I open a file and reading from it.
/*reading ten char from file and store it in buffer*/
char * buffer = malloc(sizeof(char) * 200));
fread(buffer, 1, 10, file);
The pointer in buffer always starts at 0 at the beginning
so by using fread(buffer, 1, 10, file); 20 times I should be able to fill it without overwriting anything right?
Code may be easier to explain:
What I'm wondering is if this kind of using pointers is possible and will it work.Code:char* buffer = malloc(sizeof(char)* 100); /*set null from buffer to buf, 30 bytes*/ memset(buffer, '\0', 30); /*since buffer is pointing at buf now it will start storing from there, therefore storing data from buffer to buffer*/ fread(buffer, 1, 30, a_file); /*will set 0 from buffer to buffer*/ memset(buffer, '\0', 10); fread(buffer, 1, 30, a_file); /*after this the data from file will be stored in buffer to buffer*/
Thanks for reply.