Advertisement
Guest User

Fixed moving window.

a guest
Apr 3rd, 2016
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5.  
  6. int main(){
  7.  
  8. setbuf(stdout,NULL); //disable output buffering
  9.  
  10. char *str=malloc(9);
  11. strcpy(str,"abcdefgh");
  12.  
  13. str=realloc(str,strlen(str)+1+8);
  14. strcat(str,"efghefgh"); //sprintf(str,"%s%s",str,"efghefgh");
  15.  
  16. unsigned int imax=1024/strlen(str)*1024*4;
  17.  
  18. printf("%s","exec.tm.sec\tstr.length\n"); //fflush(stdout);
  19.  
  20. time_t starttime=time(NULL);
  21. char *gstr=malloc(0);
  22. unsigned int i=0;
  23. size_t lngth;
  24.  
  25. char *pos_c=gstr;
  26. size_t str_len=strlen(str);
  27.  
  28. while(i++ < imax+1000){
  29. lngth=strlen(str)*i;
  30. gstr=realloc(gstr,lngth+str_len);
  31. strcat(gstr,str); //sprintf(gstr,"%s%s",gstr,str);
  32. pos_c=(gstr + (str_len * (i - 1)));
  33.  
  34. while((pos_c=strstr(pos_c,"efgh"))){
  35. memcpy(pos_c,"____",4);
  36. }
  37.  
  38. if(lngth % (1024*256)==0){
  39. printf("%lusec\t\t%lukb\n",time(NULL)-starttime,lngth/1024); //fflush(stdout);
  40. }
  41. }
  42. //printf("%s\n",gstr);
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement