September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
18
Task/Rep-string/C/rep-string-2.c
Normal file
18
Task/Rep-string/C/rep-string-2.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// strstr : Returns a pointer to the first occurrence of str2 in str1, or a null pointer if str2 is not part of str1.
|
||||
// size_t is an unsigned integer typ
|
||||
// lokks for the shortest substring
|
||||
int repstr(char *str)
|
||||
{
|
||||
if (!str) return 0; // if empty input
|
||||
|
||||
size_t sl = 1;
|
||||
size_t sl_max = strlen(str) ;
|
||||
|
||||
while (sl < sl_max) {
|
||||
if (strstr(str, str + sl) == str) // How it works ???? It checks the whole string str
|
||||
return sl;
|
||||
++sl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue