[Courses] [C Doubt]

sneha sneha at vit.ac.in
Wed Sep 18 20:36:05 EST 2002


**thank u :)
anyway... I wrote my own function...
friendly
sneha :o)

#include<stdio.h>
char *substr(char *,int,int);
main()
{
char *str="programming",*str1;
int s=3,e=7;
str1=substr(str,s,e);
printf("The substring is : %s\n",str1);
}

char *substr(char *str,int s,int e)
{
int i,j=0;
char *str1;
str1=(char *)malloc(strlen(str));
for(i=s-1;i<e;i++,j++)
    str1[j]=str[i];
return str1;
}        

----- Original Message ----- 
From: Malcolm-Rannirl <rannirl-lc at otherkin.net>
To: sneha <sneha at vit.ac.in>
Sent: Wednesday, September 18, 2002 8:08 PM
Subject: Re: [Courses] [C Doubt]


> On Wednesday 18 September 2002 10:11 am, sneha wrote:
> > Hello all :)
> > Is there any function in c to get a substring from an existing string..
> 
> There's:
> 
> (man strstr)
>  char *strstr(const char *haystack, const char *needle);
> 
> DESCRIPTION
>        The  strstr()  function  finds  the first occurrence of the substring 
> needle in the string haystack. The terminating `\0' characters are not 
> compared.
> 
> Which will find a string for you, or if you want to copy a string from an 
> existing string, any of the string copy functions (strcpy or strncpy) will 
> work.
> 
> 
> 
> -- 
> Be careful what you want.
> It might want you.
> - 'the Dragon' Elvendrums
> 
> <<------------------------------------------------------------------>>
> <<  This email is monitored by the US government under the auspice  >>
> << of the USA act. For private communication, ask me for my PGP key >>
> << ----- PGP: envelopes for email - www.pgp.com www.gnupg.org ----- >>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://linuxchix.org/pipermail/courses/attachments/20020918/174e7e44/attachment.xhtml


More information about the Courses mailing list