Re: need some help
- From: Richard Heathfield <invalid@xxxxxxxxxxxxxxx>
- Date: Fri, 09 Jun 2006 17:44:51 +0000
Fred Kleinschmidt said:
"Richard Heathfield" <invalid@xxxxxxxxxxxxxxx> wrote in message
news:dcqdncLBzsurHBTZRVnytQ@xxxxxxxxx
ash said:
hi friends,
i have some questions whch is in my last year question papers.i need
some help to get logic of these questions.
1) write a C function, that takes two strings as arguments and returns
a pointer to the first occurrence of 1st string in 2nd string or NULL
if it is not present.
Well, that one's easy, at any rate.
#include <string.h>
char *ashstrstr(char *haystack, char *needle)
{
return strstr(haystack, needle);
}
This is wrong. It should be strstr(needle, haystack).
<sigh> The easy ones are always hardest.
The instruction was to find first occurence of s1 in s2.
strstr finds first s2 in s1.
Quite right. My apologies.
For this homework, I think the instructor really wants
the student to write the internals of strstr.
Yes, but here in comp.lang.c we try to get the OP to think, rather than
spoonfeed them a solution. In this case, I was trying to get him (or
possibly her - I haven't checked) to think about how to phrase the
question. Shame I messed up the answer, though...
If so, he/she
should have explicitly stated that using strstr was not allowed.
Precisely so.
<snip>
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.
- References:
- need some help
- From: ash
- Re: need some help
- From: Richard Heathfield
- Re: need some help
- From: Fred Kleinschmidt
- need some help
- Prev by Date: Re: casting
- Next by Date: Re: Structure of functions
- Previous by thread: Re: need some help
- Next by thread: Re: need some help
- Index(es):
Relevant Pages
|