strstr æååä¸ã®æååã®æ¤ç´¢; æ¼ç¿åé¡2. strstr æåå1ããæåå2ãæ¤ç´¢ãã ãæ¸å¼ã #include char *strstr(const char *s1, const char *s2); ã説æã æåå s1 ã®å
é ããæåå s2 ãæ¢ããè¦ã¤ãã£ãã¨ãã«ã¯ãã®ä½ç½®ããã¤ã³ã¿ã§è¿å´ããè¦ã¤ãããªãã£ãã¨ãã«ã¯NULLãè¿å´ãã¾ãã ãå¼æ°ã ããã > Cè¨èª > Cè¨èª æåå12(strcmpé¢æ°ã®èªä½) ãã®åºåã¯ã90æ¥ä»¥ä¸æ´æ°ãã¦ããªãããã°ã«è¡¨ç¤ºãã¦ãã¾ãã 2015 - 06 - 29 æå Cè¨èªã§ã¯ char åï¼æååï¼ï¼char 㯠character ã®ç¥ï¼ã¨ãããã¼ã¿åããããããã¯1ãã¤ãã®ã¡ã¢ãªãµã¤ãºããã¤ãã¼ã¿åã§ããã ããã°ã©ãã³ã° Cè¨èª rev (&vc[0], n); ã®&vc[0]ã¯ã©ã®ãããªæå³ãæã£ã¦ããã®ã§ããããã ä¸è¡ç®revé¢æ°ã®int *vcãããã¤ã³ã¿å¤æ°ãªã®ã§ãé
åã®å
é å¤vc[0]ã¨ç¹å®ã®å¤ã代å
¥ããã®ã¯ã¾ãããªãã®ã§ ⦠ANSI C æ¨æºã§ã¯ãªããã©ãã£ã¦ããã¨ã¯ malloc ãã¦ã³ãã¼ãã¦ãã ããªã®ã§èªä½ããã®ã¯å®¹æ. cè¨èªããã°ã©ãã³ã°é¢æ°èªä½ æ大å¦æ
å ±ç³»å¦é¨åºèº«ã®ç®¡ç人ãéå»ã«ææ¥ã§ä½æããã½ã¼ã¹ã³ã¼ããè¼ãã¦ããã¾ãã ããã¯Cè¨èªã«ãè«çåãã¨ãããã®ãæ確ã«å®ãã¦ããªããã¨ã«ããè½ã¨ãç©´ã§(ã¨ãããè«çåã¨ããåã¯ããã¾ãã)ï¼Cè¨èªã®ã¨ãã¹ãã¼ãã¨å¼ã°ãã人ãã¡ã¯ifæãªã©ã§ã®è«çã®å¤æã¯â1ï¼0"ã§ã¯ãªãâé0ï¼0"ã§è¡ããã®ã ã¨ç¥ã£ã¦ãã¾ãã ãã®ãããstrstré¢æ°ã§æ§æååãè¦ã¤ãã¦æ°æååãå
¥ãæ¿ããå¦çã¯ã1åããã§ã¯ä¸å®å
¨ã§ããwhileã«ã¼ãã§ãæ§æååãè¦ã¤ãããªããªãã¾ã§ãç¹°ãè¿ããªããã°ãªãã¾ããã while ((p = strstr(buf, str1)) != NULL) { : atoié¢æ°ãèªä½ããä¾ã§ããCè¨èªããã°ã©ãã³ã°ã®åèã«ãªããããªTipsãã¯ã¤ãºã®ãã¼ã¸ã§ãã strã®ä¸ããchrãæ¤ç´¢ãã¦æåã«çºè¦ããæå以éã®ã¢ãã¬ã¹ãè¿ããæåãçºè¦ã§ããªãã£ãå ´åã¯NULL(\0)ãè¿ãã Cè¨èªã«ã¯ substring ã¯ç¨æããã¦ãã¾ããã ä»åã¯ã次ã®2ã¤ã®ä¾ã§é¨åæååãåãåºãæ¹æ³ãç´¹ä»ãã¾ãã (1) strncpy ã使ã (2) substring é¢æ°ãèªä½ãã (1) strncpy ã§é¨åæååãåãåºã Cã»C++ã»C# - 課é¡ã§ strstr()ã¨åãåããããmy_strstr()ãå®è£
ããªããã¨ãã課é¡ãã§ã¦ãã¾ãã strstr()㯠char *strstr(const char *s strcasestr() é¢æ°ã¯ã strstr() ã¨åæ§ã§ããã両æ¹ã®æååãç¡è¦ãã¾ãã. å±
ãé«ãã§ããï¼å
¥éæ¸ãèªã¿çµããå¾ã«èªãã¨é常ã«æçã§ãï¼ Cè¨èªã§ã¯æå®æåãæ¤ç´¢ããæ¹æ³ã¨ãã¦strchré¢æ°ããæå®æååãæ¤ç´¢ããæ¹æ³ã¨ãã¦strstré¢æ°ãç¨æããã¦ãã¾ãã ã©ã¡ãããããã¼ãã¡ã¤ã«ãstring.hããã¤ã³ã¯ã«ã¼ããã¦ä½¿ç¨ãã¾ãã TRUE ã«ããã¨ã stristr() ã®è¿ãå¤ã¯ãhaystack ã®ä¸ã§æåã« needle ããããããç®æããåã®é¨åã¨ãªãã¾ã (needle ã¯å«ãã¾ãã)ã ãã®ç« ã®æ¦è¦. before_needle. ç¬ã§ãã ä»åã¯æååãæ¯è¼ããæ¹æ³ã«ã¤ãã¦ãã£ããã«å¦ãã§ããã¾ããããæååã®æ¯è¼ã«ã¯strcmpãstrncmpã¨ããé¢æ°ã使ãã¾ããã¹ããªã³ã°ã³ã³ãã¢ã¼ã¨èªã¿ã¾ ⦠ã«å¯¾å¿ããæåã¨ãã¦æ±ãã¾ãã. å±
ãé«ãã§ããï¼å
¥éæ¸ãèªã¿çµããå¾ã«èªãã¨é常ã«æçã§ãï¼ ãã®ç« ã®æ¦è¦ã§ãã ç®ç; æ¹æ³â ï¼strstré¢æ°ã使ãï¼ ç®ç. memcpy,memcmp,strcmp,strlen,strcat,strcpy,strstr,strchr以ä¸ã®é¢æ°ãèªä½ãã¾ãããã²ã¨ã¤ã²ã¨ã¤ãè¦ãã¨ãã«åä½ã確èªããã¨ãããã¾ãåºæ¥ãã®ã§ããããã®é¢æ°ãããã°ã©ã ã«çµã¿è¾¼ãã ã¨ãããã¾ãåä½ãã¾ããã§ãããã©ããé ã¹ãã ã³ã¼ã«é¢æ°ã§ãã¡ã¤ã«å
¥åºå(1) ä½ç½®æ
å ±ã使ã£ãAndroidã¢ããªãä½ãéã®åèã¡ã¢ ãCè¨èªãstrcaté¢æ°ãèªä½ãã¦ã¿ããã第äºå¼¾ã ãCè¨èªãstrlené¢æ°ãèªä½ãã¦ã¿ããã第ä¸å¼¾ã offline access tokenããªããªãã®ã§ããããã¾ã¨ã; 6æ (7) Cè¨èªã«ããã¦æ
å ±ã®æ¯è¼ãè¡ãããæãããã¾ããæååãé
åã¨ãã£ãè¤æ°ã®æ
å ±ã§æ§æããããã®ã¯æ¯è¼æ¼ç®åã使ããªããããstrcmpé¢æ°ãmemcmpé¢æ°ãå©ç¨ãã¦ä¸è´å¤å®ãè¡ãã¾ãã strstr() é¢æ°ã¯ããã«æåã§çµäºããæåå big ä¸ã§ããã«æåã§çµäºããæ åå little ãæåã«åºç¾ããä½ç½®ãæ¢ãã¾ãã. K&Ræ¬ æ¼ç¿5-5 ãã®å¼æ°ã§ããæååã®æåã®æ大 n æåãæ±ã⦠æååã®ä¸ãããä»»æã®æååãæ¢ãããã¨ãã¾ãã ¨-- éå¼ã. å
é ã¸æ»ã. Cè¨èª strstr 使ãæ¹ ä»åã¯Cè¨èªã®strstré¢æ°ã«ã¤ãã¦èª¬æãã¾ãã strstré¢æ°ã¯æååããæååãæ¤ç´¢ãã¦ãã®å ´æã®ãã¤ã³ã¿ãè¿ãã¦ãããé¢æ°ã§ãã 2016/03/04 cè¨èªãc++ã®ãã¼ã¸ã®ã½ã¼ã¹ã³ã¼ããä¸é¨ä¿®æ£ 2014/01/31 cè¨èªé¢æ°ä¸è¦§ãã¼ã¸ã«11ãã¼ã¸ã»ã©è¿½å 2014/01/31 cè¨èªé¢æ°ä¸è¦§ãã¼ã¸ã«30ãã¼ã¸ã»ã©è¿½å 2014/01/30 cè¨èªé¢æ°ä¸è¦§ãã¼ã¸ä½ ⦠æååãå¶å¾¡ããããã«ã¯ã¡ã¢ãªã»é
åã»ãã¤ã³ã¿ã®ç¥èãæ¬ ããã¾ããããããã®ç¥èãå¦ãã ãã¨ã ããããæååå¶å¾¡ã®é£ãããç¥ããã¨ãã§ããã®ã§ããæååãæ±ãä¸ã§å±éºãªãã¨ããã£ã¦ã¯ãªããªããã¨ãç解ãã¾ãããã