User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 402,632 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,299 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Jul 11th, 2005
Views: 1,300
How might I write an implementation in C of the standard library function strstr? Here's how I might.
c Syntax | 4 stars
  1. #include <stdio.h>
  2.  
  3. char *mystrcat(char *dst, const char *src)
  4. {
  5. char *start = dst;
  6. while ( *dst )
  7. {
  8. ++dst; /* find the current end of the string */
  9. }
  10. while ( *dst++ = *src++ )
  11. ; /* copy from 'src' up to and including the terminating null character */
  12. return start;
  13. }
  14.  
  15. int main (void)
  16. {
  17. char text[12] = "Hello";
  18. puts(mystrcat(text, " world"));
  19. return 0;
  20. }
  21.  
  22. /* my output
  23. Hello world
  24. */
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 2:07 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC