Re: K&R2, exercise 5.4
- From: arnuld <arnVuld@xxxxxxxxxxxxx>
- Date: Wed, 09 Apr 2008 16:53:38 +0500
On Wed, 09 Apr 2008 16:44:13 +0500, arnuld wrote:
I have come up with following and it runs fine. Any of you finds a
run-time bug in it ?
that has a bug :( , this is the newer version free of bugs. Do you have
any advice in this program:
#include <stdio.h>
#include <stdlib.h>
int strend( char*, char* );
int main()
{
char s[] = "Love";
char t[] = "Loved";
printf("\n%d\n", strend(s,t));
return EXIT_SUCCESS;
}
/* I am using pointers because, arrays are never passed to functions and I
* don't want to FAKE the array call
*
* outer for loop checks for each element of 1st array.
* inner for loop compares elements of both arrays.
* if condition checks whether we have compared the 2nd array till end.
*/
int strend( char* s, char* t )
{
char *pj;
for( ; *s != '\0'; *s++ )
{
for( pj = s; *t == *pj; t++, pj++ )
{
;
}
if( *t == '\0' )
{
return 1;
}
}
return 0;
}
--
http://lispmachine.wordpress.com/
Please remove capital 'V's when you reply to me via e-mail.
.
- Follow-Ups:
- Re: K&R2, exercise 5.4
- From: arnuld
- Re: K&R2, exercise 5.4
- References:
- K&R2, exercise 5.4
- From: arnuld
- Re: K&R2, exercise 5.4
- From: arnuld
- K&R2, exercise 5.4
- Prev by Date: Re: C FAQs 6.12
- Next by Date: recursion.
- Previous by thread: Re: K&R2, exercise 5.4
- Next by thread: Re: K&R2, exercise 5.4
- Index(es):
Relevant Pages
|