Guest User

Untitled

a guest
Jan 5th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. bool is_prefix(char* str1, char* str2){
  2.  
  3. if(str1[0]=='\0'){
  4. return true;
  5. }
  6.  
  7. if(str1[0]==str2[0]){
  8. return is_prefix(str1+1,str2+1);
  9. }
  10.  
  11. return false;
  12.  
  13. }
  14.  
  15. int substring_position(char* str1, char* str2){
  16.  
  17. if(is_prefix(str1,str2) == true){
  18. return 0;
  19. }
  20.  
  21. if(str2[0] != '\0'){
  22. if(1+substring_position(str1,str2+1)>0){
  23. return 1+substring_position(str1,str2+1);
  24. }
  25. }
  26.  
  27. return -1;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment