子串查詢函式strstr
/************************ * Project Name : String Operation Functions * Module Name : Strstr.c * Create : 2010-04-24(Sat) * Update : 2010-04-24(Sat) * Copyright : Micheal Zhong * Reference : ************************/ #include<stdio.h> int strstr( char *master, char *slave ) { char *m = master; char *s = slave; int count = 0; int temp = 0; while( *m != '/0' )//go to the tail of the master { while( *m != '/0' && *m != *s ) //find the first char of slave in master { m++; count++;//count addition follows m } if( m == '/0' ) //do not exist the first char of slave in master printf("DO NOT EXIST! CUP!/n"); else temp = count; //exist the first char of slave in master //save its position to temp while( *m == *s && *s != '/0' && *m != '/0' ) //compare slave and master until m != s //or get the end of master or slave { m++; count++;//count addition follows m s++; } if( *s == '/0' ) //get the end of slave //which means slave exists in master { return temp; //output the position of the slave's head in master if( *m == '/0' ) //get the end of master exit(0); else s = slave; //maybe slave appears more than one time in master } else if( *m == '/0' )//get the end of slave, then halt { printf( "DO NOT EXIST! CUP!/n" ); exit(0); } else if( *m != *s ) //The slave's head is similar to the master's substring //but do not match { s = slave; m = master + temp + 1; count = temp + 1; } } }
相關文章
- 子串查詢
- 查詢子串
- 子串查詢;及排列子串分析
- #103. 子串查詢
- 糖果;及子串查詢分析
- strstr函式函式
- Python小技巧 - 子串查詢Python
- (函式)實現strstr函式函式
- C 庫函式 - strstr()函式
- [LeetCode] Implement strStr() 實現strStr()函式LeetCode函式
- 5. PHP 函式 strstr ()PHP函式
- BMH子串查詢演算法(PHP實現)演算法PHP
- 子查詢-表子查詢
- Solr複雜查詢一:函式查詢Solr函式
- 【SQL】使用分析函式與關聯子查詢的比較SQL函式
- PHP字串函式之 strstr stristr strchr strrchrPHP字串函式
- PostgreSQL 查詢替換函式SQL函式
- Solr的函式查詢(FunctionQuery)Solr函式Function
- SQL 部分函式的使用,子查詢,group by,虛擬欄位,case……SQL函式
- 【從零開始學習Oracle資料庫】(3)函式與子查詢和連線查詢Oracle資料庫函式
- 【從零開始學習 MySql 資料庫】(3) 函式與子查詢和連線查詢MySql資料庫函式
- 複雜查詢—子查詢
- Java-MySql-函式、多表查詢JavaMySql函式
- [Mysql 查詢語句]——集合函式MySql函式
- SQL查詢中用到的函式SQL函式
- iPhone查詢序列號生成函式iPhone函式
- SQL查詢的:子查詢和多表查詢SQL
- 相關子查詢&非相關子查詢概念
- MySQL子查詢MySql
- 使用子查詢
- MYsql 子查詢MySql
- oracle子查詢Oracle
- 子查詢分解
- 11子查詢
- sql子查詢SQL
- informix子查詢ORM
- c++字串查詢函式實現C++字串函式
- 二分查詢(函式實現)函式