keker123

Untitled

May 12th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. void rotate() {
  2.     fclose(filelogs);
  3.     char tmp[100];
  4.     strcpy(tmp, fileName);
  5.     int count = 0;
  6.     while(access(tmp, F_OK) == 0) {
  7.         count++;
  8.         sprintf(tmp, "%s.%d", fileName, count);
  9.     }
  10.     for(int i = count; i > 0; i--){
  11.         char newname[100], oldname[100];
  12.         if(i==1){
  13.             strcpy(oldname, fileName);
  14.         }
  15.         else{
  16.             sprintf(oldname, "%s.%d", fileName, i-1);
  17.         }
  18.         sprintf(newname, "%s.%d", fileName, i);
  19.         rename(oldname, newname);
  20.     }
  21.     filelogs = fopen(fileName, "w");
  22. }
Advertisement
Add Comment
Please, Sign In to add comment