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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:17:53+00:00 2026-05-15T19:17:53+00:00

How can one compare a string from the middle (or some other point but

  • 0

How can one compare a string from the middle (or some other point but not the start) to another string?
like i have a string
str1[]=”I am genius”;
now if i want to find a word in it how should i compare it with the word? for example the word is am.
Here is what i did.Its a bit stupid but works perfectly 😀

#include<stdio.h>

  #include<string.h>
  void print( char string[]);
  int  main()
{
  int i;
  char string1[20];
  printf("Enter a string:");
  gets(string1);
  print(string1);
  return 0;
  getch();
}
void print(char string[])
{
    int i,word=1,sum=0,x;

    for(i=0;    ;i++)
    {
    sum++;

    if(string[i]==' ')
    {
        printf("Word#%d:%d\n",word,sum-1);
        sum=0;
        word++;
    }/* if ends */
     if(string[i]=='\0')
     {    // program sai kaam karnay k liye ye code yahan bhi paste hona chahyey
        printf("Word#%d:%d\n",word,sum-1);
        sum=0;
        word++;
        break;
    }
    }/* for ends*/


}
  • 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-15T19:17:54+00:00Added an answer on May 15, 2026 at 7:17 pm

    Use strncmp():

    strncmp( whereToFind + offsetToStartAt, patternToFind, patternLength );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for some SQL varchar comparison function like C# string.compare (we can
How can one load custom (not an image, nor a sound file) resource file
How can one remove all text, but leave the structure intact? for example: <animals>
How can one interface with Google Sketchup , via the API, from a Windows
How can one ignore Unexpected element situation in JAXB ans still get all other
How can one specify the connection string in a config file of a class
I want to compare and select a field from DB using Like keyword or
If all tables I want to delete from have the column gamer_id can i
i have a java class like this public class A { private String field1;
I am trying to capture sub-strings from a string that looks similar to 'some

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.