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

  • Home
  • SEARCH
  • 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 1045521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:59:53+00:00 2026-05-16T15:59:53+00:00

I have made strstr() function but the program does not give any output,just a

  • 0

I have made strstr() function but the program does not give any output,just a blank screen.Please have a look at the code.

#include<stdio.h>
#include<conio.h>

    const char* mystrstr(const char *str1, const char *str2);
    int main()
    {
        const char *str1="chal bhai nikal";
        const char *str2="nikal",*result;
        result=mystrstr(str1,str2);
        printf("found at %d location",(int*)*result);
        getch();
        return 0;


    }
    const char * mystrstr(const char *s1, const char *s2)
    {
        int i,j,k,len2,count=0;
        char *p;
        for(len2=0;*s2!='\0';len2++);//len2 becomes the length of s2
        for(i=0,count=0;*s1!='\0';i++)
        {
            if(*(s1+i)==*s2)
            {
                for(j=i,k=0;*s2!='\0';j++,k++)
                {
                    if(*(s1+j)==*(s2+i))
                    count++;
                    if(count==len2)
                    {
                        p=(char*)malloc(sizeof(char*));
                        *p='i';
                    return p;
                    }
                }

            }

        }
        return NULL;
    }
  • 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-16T15:59:53+00:00Added an answer on May 16, 2026 at 3:59 pm

    The line with this comment:

    //len2 becomes the length of s2
    

    is broken. You repeatedly check the first character of s2. Instead of *s2, try s2[len2].

    Edit: as others have said, there are apparently a lot more things wrong with this implementation. If you want the naive, brute-force strstr algorithm, here’s a concise and fast version of it:

    char *naive_strstr(const char *h, const char *n)
    {
        size_t i;
        for (i=0; n[i] && h[i]; i++)
           for (; n[i] != h[i]; h++) i=0;
        return n[i] ? 0 : (char *)h;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a cart and the cart has remove item button, but the
I have made my Actor , but I am unclear on how to take
I have made a player that plays mp3 and does the job very well
I have made an mvc3 application with Windows Authentication. Everything works fine but I
I have made a simple timer but in trying to increase the timers speed
I have made a small program in C# that I want to run in
I have made a custom sort of wrapper for the JQuery's Ajax function and
I have made an AJAX chatroom; and it works in chrome and FF, but
I have made this game for Mac OS, but I realised that i need
I have made little program for computing pi (π) as an integral. Now 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.