Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Codeplaza/7317142 to your computer and use it in GitHub Desktop.

Select an option

Save Codeplaza/7317142 to your computer and use it in GitHub Desktop.
/*given the length it should print all the repeated strings in the word of that particular length*/
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,k,l,p=0,f,q=0,t;
char s[100];
printf("\nenter the word:");
gets(s);
textcolor(YELLOW);
cprintf("\nenter the length of the string to be repeated twice:");
scanf("%d",&f);
textcolor(GREEN);
cprintf("\nThe strings which are repeated are:");
printf("\n");
for(i=f;s[i]!='\0';i++) /*it is required to test for repetition from the value of the given length as there can be no repetition before that */
{
for(j=i-f;j>=q-1;j--) /* comparision of the word must start from the current position -length given.....if matched then check for the next element else decrement j*/
{
for(k=i,l=j;k<i+f;k++,l++) /*compare two words till the length is equal to the given length*/
{
if(s[k]==s[l])
{
p++;
if(p==f)
{
q=l;
textcolor(1+i);
for(t=i;t<i+f;t++)
{
cprintf("%c",s[t]);
}
printf("\n");
}
}
else
{
k=i;l=j;p=0;break;
}
}
}
}
getch();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment