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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:47:23+00:00 2026-05-16T16:47:23+00:00

The code says at many places invalid indirection.Please help. int main() { char *s1,*s2,*position;

  • 0

The code says at many places “invalid indirection”.Please help.

   int main()
    {

        char *s1,*s2,*position;
        printf("Enter string:\n");
        gets(s1);
        printf("Enter word to find:\n");
        gets(s2);
        *position=ststr(*s1,*s1);
        if(*position)
        printf("word is found at %c loc\n",*position);
        else
        printf("word not found");
        getch();
        return 0;

    }

char *strstr(char *s1,char *s2)
{
    int flag=1;
    char i,j;
    for(i=0; ;i++)
    {
        if(*s1[i]==*s2[0])
        for(j=i;*s2;j++)
        {
            if(*s1[j]!=*s2[j])
            flag=0;
        }

    }
    if(flag)
    return i;
    else
    return 0;
}
  • 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-16T16:47:24+00:00Added an answer on May 16, 2026 at 4:47 pm

    First, s1 and s2 in main have not been initialized to point anywhere meaningful. Either declare them as static arrays, or allocate memory to them at runtime using malloc() or calloc():

    #define SIZE 20 // or some number big enough to hold your input
    ...
    char s1[SIZE], s2[SIZE], *position; // s1 and s2 declared statically
    

    Second, NEVER NEVER NEVER NEVER NEVER use gets(); it will introduce a point of failure in your program. Use fgets() instead:

    if (fgets(s1, sizeof s1, stdin) != NULL)
      // process s1
    else
      // check for EOF or error on read
    

    EDIT

    And like everyone else has pointed out, your comparison in the strstr() function needs to be either

    *s1 == *s2
    

    or

    s1[i] == s2[i]
    

    but first you need to deal with allocating your buffers in main properly.

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

Sidebar

Related Questions

If my page says: Code incorect please try again then my URL redirect should
Title says all. Sample code: ArrayList<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>(); HashMap<String, Object>
ok, I guess the code says it all. //I have this string. var str
Eclipse is giving me many errors for one specific line of code says: Multiple
The code says Zend_Form_element_File::setDestination() is deprecated and to use the rename filter. However the
I am confused about why this code says JPEG files and PNG files are
I get an error in the bellow code it says I cannot convert method
In this link: http://css-tricks.com/snippets/jquery/jquery-plugin-template/ it has a line of code that says // Add
I'm reading a book that recommends clicking a check box that says Place code
this is function.php of a wordpress theme that NOD32 says this code have a

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.