fork(4) download
  1. #define MAX 1000
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<string.h>
  5. int compare(const void *a,const void *b)
  6. {
  7. return strcmp(*(char **)a,*(char **)b);
  8. }
  9.  
  10. int main()
  11. {
  12. char *ch,**suff;
  13. int count=0,i,j=0,maxlen=0;
  14. ch = (char *)malloc(sizeof(char)*MAX);
  15. suff = (char **)malloc(sizeof(char *)*MAX);
  16. printf("enter string\n");
  17. scanf("%s",ch);
  18. char *temp = ch;
  19. while(*temp++)
  20. count++;
  21.  
  22. for(i=0;i<count;i++)
  23. {
  24. suff[i] = ch+i;
  25. }
  26. qsort(suff,count,sizeof(char *),compare);
  27. for(i=0;i<count-1;i++)
  28. {
  29. j=0;
  30. while(*(suff[i]+j) && *(suff[i+1]+j) && *(suff[i]+j)==*(suff[i+1]+j))
  31. j++;
  32. if(j>maxlen)maxlen =j;
  33. }
  34. printf("maxlen is %d\n",maxlen);
  35. return 0;
  36. }
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
stdin
doomdoomdoom
compilation info
prog.c: In function ‘main’:
prog.c:17: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
stdout
enter string
maxlen is 8