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 8078643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:51:38+00:00 2026-06-05T15:51:38+00:00

I really need help with this last part of my program. I need to

  • 0

I really need help with this last part of my program. I need to find a string within a larger string and if found return the start location of the substring. From the directions:

Note that your string location starts from 0 and ends at length -1. If the string is not found, a value of -1 will be returned.

I’ve started and the following code compiles, I just want to know if this is actually correct. I don’t want to get in too over my head but I need some feedback from experts. Am I doing this right? Or at least am I going in the right direction?

const int MyString::Find(const MyString& other)
{
    int start(0);
    int counter(0);
    int end = other.Size;
    int count(0);
    int end1 = Size;
    int nfound = -1;

    char* temp;
    temp = new char[other.Size];

    if(other.String[0] != '\0' && other.String[0] != ' ')
    {
             if(other.String[count] == String[counter])
                    {
                            start = counter;

                            for(int i = count; i < end-1;i++)
                            {
                                    for(int j = counter; j < end1 -1; j++)
                                    {


                                            temp[j] = String[j];
                                    }
                            }
                            if(other == temp)
                            {
                                    return start;
                            }
                            else
                                    return nfound;
                    }

            else{
            while(other.String[count] != String[counter])
            {
                    counter++;
                    if(other.String[count] == String[counter])
                    {
                            start = counter;
                            for(int i = count; i < end-1;i++)
                            {
                                    for(int j = counter; j < end1 -1; j++)
                                    {


                                            temp[j] = String[j];
                                    }
                            }
                            if(other == temp)
                            {                 
                                    return start;                               
                            }
                            else
                                    return nfound;
                    }







            }


            }

    }
    else
    {
            return nfound;
    }





  }
  • 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-06-05T15:51:39+00:00Added an answer on June 5, 2026 at 3:51 pm

    This line is all right, though it wants a corresponding delete statement:

    temp = new char[data.Size];
    

    However, I doubt that this line does what you want:

    temp = data.String;
    

    Assuming that Mystring::String (which were more conventionally named Mystring::string, but let that pass) has the type char *, the latter line copies no characters from data.String into the buffer at temp. Instead, it loses the buffer, after which temp is just a synonym for, and points to the selfsame memory as, data.String.

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

Sidebar

Related Questions

I really need help on this one. I am having a simple login form
Sorry to bother again, but I really need help transforming this Python2 code into
I really need your help for this. I am relatively new to programming and
I really need some help with this as I have been trying to fix
We Really need some help on this one: We've Struggled with all the Apple
I really need help here. I'm desperate at this point. I have NSOperation that
For starters this is homework, I just really need help with a binary search
I really need help with the where clause below. Consider this xml <name xmlns=http://www.imsglobal.org/xsd/imslip_v1p0>
Hello i am new in android and i really need help with something. I
Well, I know absolutely nothing about the subject, so I really need help. I

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.