Last active
October 7, 2017 15:58
-
-
Save aneury1/28e2de5d39cb0c5d865a372307e60ffe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int find(const char *str, const char *sb, int beg) | |
{ | |
int whole= strlen(str), len2=strlen(sb); | |
bool found=false; | |
int i = beg; | |
for( i=beg; i < whole; i++) | |
{ | |
if( str[i] == sb[0]) | |
{ | |
found = true; | |
for( int o=0; o < len2; o++) | |
{ | |
if(str[i+o] != sb[o]) | |
{ | |
found = false; | |
break; | |
} | |
else | |
{ | |
found =true; | |
} | |
} | |
} | |
if(found == true) | |
{ | |
break; | |
} | |
} | |
if(found==true) | |
return i; | |
else | |
return -1; | |
} | |
int find(const char *str, const char *sb, int beg) | |
{ | |
int whole= strlen(str), len2=strlen(sb); | |
bool found=false; | |
int i = beg; | |
for( i=beg; i < whole; i++) | |
{ | |
if( str[i] == sb[0]) | |
{ | |
found = true; | |
for( int o=0; o < len2; o++) | |
{ | |
if(str[i+o] != sb[o]) | |
{ | |
found = false; | |
break; | |
} | |
else | |
{ | |
found =true; | |
} | |
} | |
} | |
if(found == true) | |
{ | |
break; | |
} | |
} | |
if(found==true) | |
return i; | |
else | |
return -1; | |
} | |
int find_only_word(const char *str, const char *sb, int beg) | |
{ | |
int whole= strlen(str), len2=strlen(sb); | |
bool found=false; | |
int i = beg; | |
int o; | |
for( i=beg; i < whole; i++) | |
{ | |
if( str[i] == sb[0]) | |
{ | |
found = true; | |
for( o=0; o < len2; o++) | |
{ | |
if(str[i+o] != sb[o]) | |
{ | |
found = false; | |
break; | |
} | |
else | |
{ | |
found =true; | |
} | |
} | |
} | |
if(found == true) | |
{ | |
if(str[i+o+1] == ' ' || str[i+o+1] == '\n'|| str[i+o+1] == '\0') | |
break; | |
else | |
found =false; | |
} | |
} | |
if(found==true) | |
return i; | |
else | |
return -1; | |
} | |
int count_all(const char *str, const char *tok) | |
{ | |
int counts=0; | |
int found=0; | |
while((found=find(str, tok, found))!= -1) | |
{ | |
counts++; | |
if(found == -1) | |
break; | |
else | |
found += strlen(tok); | |
} | |
return counts; | |
} | |
vector<int> get_string_pos(const char *str, const char *tok) | |
{ | |
vector<int>pos; | |
int found=-1; | |
while((found=find(str, tok, found))!= -1) | |
{ | |
if(found != -1) | |
{ | |
pos.push_back(found); | |
found += strlen(tok); | |
} | |
} | |
return pos; | |
} | |
void change_buffer_with_char(char *buffer,int len,vector<int>inpos, char ch) | |
{ | |
if(buffer == NULL || inpos.size()<=0) | |
return; | |
for(int i=0; i < inpos.size();i++){ | |
int ib = inpos[i]; | |
for(int f=0;f<len;f++) | |
{ | |
buffer[f+ib]=ch; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment