I am currently working on writing strstr from scratch. In my code, I am indexing a string and I eventually need to save a particular point on the string using another pointer. Here is the section of the code that I am struggling with:
char *save_str;
for(int i=0;i<length_str1; i++)
{
if(str1[i]==str2[0])
{
*save_str=str[i];
However, it is telling me that I cannot do this. How can I have a pointer point to a particular character in an index?
Quick Practical Answer
Extended Descriptive Boring Answer
There is a feature in “pure c” and “c++” about arrays and pointers.
When a programmer wants the address of the full array, or the first item, the “&” operator is not required, even considered as an error or warning by some compilers.
When a programmer wants the address of a particular item, then the “&” operator is required:
I read somewhere, that, these feature was added, in purpouse.
Many developer avoid this, and use pointer arithmetics, instead:
Personally, I wish, “&” should be use always, and avoid confusion.
Cheers.