前几天,同宿舍的一位同事要为一年365天每天创建一个文件夹,并且文件夹以当天的日期命名,比如1月1日对应的文件夹为0101,1月2日对应的则为0102......。

        上学的时候,因为程序设计的需要,用C语音创建过文件夹,所以决定送他一程,程序如下:#include   <stdio.h>
#include   <conio.h>
#include   <process.h>
#include   <dir.h>
#include   <string.h>

void main(){
    int i=0,j=0,counter=0;
    char fname[5];
    char month[12][3]={
        "01",
        "02",
        "03",
        "04",
        "05",
        "06",
        "07",
        "08",
        "09",
        "10",
        "11",
        "12"
    };
    char date[31][3]={
        "01",
        "02",
        "03",
        "04",
        "05",
        "06",
        "07",
        "08",
        "09",
        "10",
        "11",
        "12",
        "13",
        "14",
        "15",
        "16",
        "17",
        "18",
        "19",
        "20",
        "21",
        "22",
        "23",
        "24",
        "25",
        "26",
        "27",
        "28",
        "29",
        "30",
        "31"
    };
    char a[20]="mkdir ";
    system("mkdir helloword");
    system("cd helloword");
    for (i=1;i<=12;i++){
        strcpy(fname,month[i-1]);  
  /*      switch(i){
            case 2:
                counter=28;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                counter=30;
                break;
            default:
                counter=31;
                break;
        }*/
      if(i==2){
        counter=28;
      }
      else if (i==4||i==6||i==9||i==11){
        counter=30;
      }
      else{
        counter=31;
      }
        for(j=0;j<counter;j++){
            printf("i=%d,j=%d\n",i,j);
            fname[0]='\0';
            a[6]='\0';
            strcpy(fname,month[i-1]);
            strcat(fname,date[j]);
            strcat(a,fname);
            system(a);
        }
    }
    getch();
}