Hi! I am facing problems here... This is the coding that i compile in
linux terminal :
#include <stdio.h>
void *mymalloc(size_t request);
int main()
{
char * test;
int i = 0;
test = (char *)mymalloc(sizeof(char) * 6);
if (test == NULL)
{
printf("Malloc failed\n");
exit(1);
}
while(1)
{
test[i] = 'a';
printf("%d bytes written to memory\n", i+1);
i++;
}
return 0;
}
void * mymalloc(size_t request)
{
return sbrk(request);
}
and this is my output:
2565 bytes written to memory
2566 bytes written to memory
2567 bytes written to memory
2568 bytes written to memory
Segmentation fault
Can anyone explain to me what's actually happenning? If want to improve, how??
Thanks a lot for your help!!!