Strchr
From Nutwiki
Description
One day i find strchr in NutApi: char *strchr( const char * p, int ch) { for (;; ++p) { if (*p == ch) return ((char *) p); if (!*p) return ((char *) NULL); } /* NOTREACHED */ }
Test Environment
This sample should run on all platforms. I actually used: Nut/OS: Version 4.5.0 Hardware: ATmega128. Compiler: icc 7 Debug tool: AVR Studio
Source Code 1
- include <stdio.h>
char * test="ethernut"; char *strchr_test( char * const p, int ch) { for (;; ++p) { if (*p == ch) return ((char *) p); if (!*p) return ((char *) NULL); } /* NOTREACHED */ }
int main(void)
{ char * temp; temp=strchr_test(test,'e'); printf("%s\r\n", temp); }
the result is : temp=NULL;
Source Code 2
- include <string.h>
- include <stdio.h>
char * test="ethernut"; char *strchr_test( const char * p, int ch) { for (;; ++p) { if (*p == ch) return ((char *) p); if (!*p) return ((char *) NULL); } /* NOTREACHED */ } int main(void) { char * temp; temp=strchr(test,'e'); printf("%s\r\n", temp); } And this time the result is as we expected:
seek help
Anyone who knows reasons, please keep in touch with me. I will be very grateful to him.
email: liyongming1982@163.com from: Guangzhou,China