• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 686
  • Last Modified:

check if a string is substring of another(Easy q)

I have a string named in a variable lets say X
I have another string variable called Y
All I need to do is check if X is a subset of Y

for example if X="S1P1"
and Y= "S1P1s"
then it should give me true when i check this

Easy question,rt..
                         
0
vikasgkutty
Asked:
vikasgkutty
1 Solution
 
ankuratvbCommented:
use strstr() provided in string.h
0
 
ankuratvbCommented:
#include <stdio.h>
#include <string.h>

int main(void)
{
   char *str1 = "Borland International", *str2 = "nation", *ptr;

   ptr = strstr(str1, str2);
   printf("The substring is: %s\n", ptr);
   return 0;
}

Also,if u want substring check without case sensitivity:
convert both strings to lower or upper case using strupr() or strlwr() and then do strstr()

HTH
0
 
ankuratvbCommented:
For your e.g.

char *ptr=strstr(Y,X);
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
crazycomputersCommented:
vikasgkutty:

This is homework, isn't it?
0
 
Avik DasguptaCommented:
Absolutely, this looks nothing but a homework. These type of assignments we used to get in our semesters and of course we had to implement them without using string libraries.

Avik.
0
 
vikasgkuttyAuthor Commented:
how can this be homework, crazycomputers?
this is a very small check i wanted to do, in a project, tht I have been doing all sem,as Avik said

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now