Bus error on my creation of memset, please clarify what is going under the hood?

I have recreated the memset function and tested it against the original. It worked perfectly when I malloced for space to store an array saying 'Hello" in the main. What made this work was that I had to store the array index by index starting from 0 to the 4th and also added in the terminating null at the end as the 6th char.

The problem came up when I tried just pumping the array into the malloced memory in just one go wholistically (e.g s = "Hello", s being the pointer already initialized and had its memory allocated for it at an earlier stage.) This is when the bus error came in, I do not understand why. I would like the get clarification as to what is happening under the hood which caused this problem? Is the method I used in storing the array in the malloced memory wrong and if so why? What makes it different fro the first way I did it which I assume should store the array in a similar or the same fashion?

Below is attachment of the code segment relating to the function of topic:


Author: thisisglory
Login to Answer
Sort By:
My Answer