Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7545487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:56:32+00:00 2026-05-30T08:56:32+00:00

I am currently working on writing strstr from scratch. In my code, I am

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:56:34+00:00Added an answer on May 30, 2026 at 8:56 am

    Quick Practical Answer

    save_str = &str[i];
    

    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.

    char *myptr = NULL;
    char myarray[512];
    
    strcpy(myarray, "Hello World");
    
    // this is the same:
    myptr = myarray;
    
    // this is the same:
    myptr = &myarray[0];
    

    When a programmer wants the address of a particular item, then the “&” operator is required:

    save_str = &str[i];
    

    I read somewhere, that, these feature was added, in purpouse.

    Many developer avoid this, and use pointer arithmetics, instead:

    ...
    
    char *save_str;
    ...
    
    // "&" not required
    char *auxptr = str1;
    
    for(int i=0; i < length_str1; i++)
    {
        // compare contents of pointer, not pointer, itself
        if(*auxptr == str2[0])
        {
            *save_str = *auxptr;
        }
    
        // move pointer to next consecutive location
        auxptr++;
    }
    
    ...
    

    Personally, I wish, “&” should be use always, and avoid confusion.
    Cheers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on some performance critical code, and I have a particular situation
I'm currently working on writing report generators. For one report I need to do
I am currently working on a university project, using HTML5. I have been writing
I'm currently working on a project which will support multiple file writing specifications (imagine
I am writing an app for my company and am currently working on the
I'm currently working with PHPUnit to try and develop tests alongside what I'm writing,
I'm currently working on writing a version of the MATLAB RegionProps function for GNU
I am writing some bookmarklets for a project that I am currently working on
I'm occurring some trouble writing a basic webserver in JAVA. It's currently working fine
I'm currently working on a new web application and it's being developed using Oracle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.