Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.68 KB | None | 0 0
  1. char ** initCheckArray(int deep);
  2. int checkArray(char** checkArray,char* linkToVerify,int deep);
  3. void debugArray(char** testArray,int deep);
  4. void checkFic(int number,char* name,char* versionName);
  5. void giveRepoName(char *name);
  6.  
  7.  
  8. void giveRepoName(char *name){
  9.  
  10.     time_t secondes;
  11.     struct tm instant;
  12.     int year,day,month;
  13.     char strYear[12];
  14.     char strMonth[12];
  15.     char strDay[12];
  16.  
  17.     char *repoName = malloc(sizeof(char)*strlen(name)+8);
  18.  
  19.     time(&secondes);
  20.     instant=*localtime(&secondes);
  21.  
  22.     year = instant.tm_year+1900;
  23.     month = instant.tm_mon+1;
  24.     day = instant.tm_mday;
  25.  
  26.     printf("Year : %d , Month : %d , day : %d\n",year,month,day);
  27.  
  28.     strcpy(repoName,name);
  29.     sprintf(strYear, "%d", year);
  30.     strcat(repoName,strYear);
  31.     sprintf(strMonth, "%d", month);
  32.     strcat(repoName,strMonth);
  33.     sprintf(strDay, "%d", day);
  34.     strcat(repoName,strDay);
  35.  
  36.     printf("Repo name : %s",repoName);
  37.  
  38.     checkFic(0,repoName,repoName);
  39.  
  40. }
  41.  
  42.  
  43. void checkFic(int number,char* name,char* versionName){
  44.     int dossierValid;
  45.     char strVersion[5];
  46.     char* dossier = malloc(sizeof(char)*100);
  47.     char *path = malloc(sizeof(char)*100);
  48.     strcpy(path,"C:\\Users\\mathi\\Desktop\\");
  49.  
  50.     strcpy(dossier,path);
  51.     strcat(dossier,versionName);
  52.     puts(access(dossier, 0) ? "Absent" : "Present");
  53.     dossierValid = access(dossier, 0);
  54.  
  55.     if (dossierValid != 0){
  56.         mkdir(dossier);
  57.     }else{
  58.         printf("Le dossier existe deja");
  59.         strcpy(versionName,name);
  60.         strcat(versionName,"-");
  61.         number++;
  62.         sprintf(strVersion, "%d", number);
  63.         strcat(versionName,strVersion);
  64.         printf("\nNouveau nom : %s",versionName);
  65.         checkFic(number,name,versionName);
  66.  
  67.     }
  68. }
  69.  
  70. char ** initCheckArray(int deep){
  71.  
  72.     int i;
  73.  
  74.     char ** newArray = malloc(sizeof(char)*deep);
  75.  
  76.     for(i = 0 ; i <= deep ; i++){
  77.  
  78.         newArray[i] = malloc(sizeof(char)*200);
  79.  
  80.         strcpy(newArray[i],"empty");
  81.  
  82.     }
  83.  
  84.     return newArray;
  85.  
  86. }
  87.  
  88.  
  89.  
  90. int checkArray(char** checkArray,char* linkToVerify,int deep){
  91.  
  92.     int i;
  93.  
  94.     for(i = 0 ; i < deep ; i++){
  95.  
  96.         if(strcmp(checkArray[i],linkToVerify)==0){
  97.  
  98.             return 0;
  99.  
  100.         }
  101.  
  102.     }
  103.  
  104.     for(i = 0 ; i < deep ; i++){
  105.  
  106.         if(strcmp(checkArray[i],"empty")==0){
  107.  
  108.             strcpy(checkArray[i],linkToVerify);
  109.  
  110.             return 1;
  111.  
  112.         }
  113.  
  114.     }
  115.  
  116.     return 2;
  117.  
  118. }
  119.  
  120.  
  121.  
  122. void debugArray(char** testArray,int deep){
  123.  
  124.     int i;
  125.  
  126.     printf("\n\n\n\n");
  127.  
  128.     printf("Verif size : %d",deep);
  129.  
  130.     for(i = 0 ; i < deep ; i++){
  131.  
  132.         printf("\n Debug array[%d] : %s",i,testArray[i]);
  133.  
  134.     }
  135.  
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement