fork(1) download
  1. #include <stdio.h>
  2. #include <string.h>
  3. void func(char *b)
  4. {
  5. char *a= b + 1;
  6. printf("input = %s\n", b);
  7. while (*a)
  8. {
  9. if (strlen(a) == (int)(a - b) && strncmp(a, b, strlen(a)) == 0)
  10. {
  11. printf("repeat = %.*s\n\n", (int)(a - b), b);
  12. return;
  13. }
  14. ++a;
  15. }
  16. printf("repeat unit not found!\n");
  17. return;
  18. }
  19. int main()
  20. {
  21. func("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
  22. func("123412312341231234123123412312341231234123");
  23. func("oxoxoxoxoxoxoxoxxoxoxoxoxoxoxoxoxx");
  24. func("axaxa");
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
input  = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
repeat = aaaaaaaaaaaaaaaaaaa

input  = 123412312341231234123123412312341231234123
repeat = 123412312341231234123

input  = oxoxoxoxoxoxoxoxxoxoxoxoxoxoxoxoxx
repeat = oxoxoxoxoxoxoxoxx

input  = axaxa
repeat unit not found!