Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-04-11
6
Medium Priority
?
682 Views
Last Modified: 2012-06-27
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
Comment
Question by:vikasgkutty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10801048
use strstr() provided in string.h
0
 
LVL 9

Accepted Solution

by:
ankuratvb earned 75 total points
ID: 10801055
#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
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10801108
For your e.g.

char *ptr=strstr(Y,X);
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 5

Expert Comment

by:crazycomputers
ID: 10801406
vikasgkutty:

This is homework, isn't it?
0
 
LVL 2

Expert Comment

by:Avik Dasgupta
ID: 10801442
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
 

Author Comment

by:vikasgkutty
ID: 10801475
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

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question