1 #include <stdio.h> 2 #include <time.h> 3 #include <dir.h> 4 void str(char * ch, char * q); 5 void strname(char * filename, char * name, double version); 6 void cat(char * p, char * q, char * r); 7 int main() 8 { 9 char filename[100]; 10 char name[100]; 11 char name1[100]; 12 char name2[100]; 13 char ch = 0; 14 int i; 15 double version = 0.01; 16 FILE * p, * q, * r; 17 while (1) 18 { 19 system("cls"); 20 printf(" 请输入文件名: "); 21 scanf("%s", filename); 22 p = fopen(filename, "r"); 23 if (p == NULL) 24 continue; 25 break; 26 } 27 time_t t; 28 time(&t); 29 struct tm * tt = localtime(&t); 30 str(filename, name); 31 q = fopen(filename, "r+"); 32 if (q != NULL) 33 { 34 version = 0; 35 while (ch != 'v') 36 fread(&ch, 1, 1, q); 37 for (i = 0; i < 10; i++) 38 fread(&ch, 1, 1, q); 39 while (ch != '.') 40 { 41 version = version * 10 + ch - '0'; 42 fread(&ch, 1, 1, q); 43 } 44 fread(&ch, 1, 1, q); 45 version += (ch - '0')*0.1; 46 fread(&ch, 1, 1, q); 47 version += (ch - '0')*0.01; 48 strname(filename, name1, version); 49 cat(name, name1, name2); 50 r = fopen(name2, "w+"); 51 if (!r) 52 { 53 if (mkdir(name)) 54 { 55 printf("\n 创建目录失败。。。"); 56 getch(); 57 return 0; 58 } 59 r = fopen(name2, "w+"); 60 } 61 fseek(q, 0, 0); 62 while (1) 63 { 64 fread(&ch, 1, 1, q); 65 if (feof(q)) 66 break; 67 fwrite(&ch, 1, 1, r); 68 } 69 fclose(q); 70 fclose(r); 71 version += 0.01; 72 } 73 q = fopen(filename, "w+"); 74 char * string = "/*******************************************************************************\n name: %s \n version: %.2f\n author: 神☆雕 \n time: %s qq: 438985635 \n e-mail: 438985635@qq.com \n Copyright(c) 2010 - 2012 shendiao.All Rights Reserved.\n*******************************************************************************/\n\n"; 75 fprintf(q, string, name, version, asctime(tt)); 76 while (1) 77 { 78 fread(&ch, 1, 1, p); 79 if (feof(p)) 80 break; 81 fwrite(&ch, 1, 1, q); 82 } 83 fclose(p); 84 fclose(q); 85 printf("\n 成功生成文件: %s", filename); 86 getch(); 87 return 0; 88 } 89 90 void str(char * ch, char * q) { 91 int i = 0; 92 int j; 93 while (ch[i] && ch[i] != '.') 94 { 95 q[i] = ch[i]; 96 i++; 97 } 98 q[i] = 0; 99 j = i; 100 while (ch[i++]); 101 while (i >= j) 102 { 103 ch[i+4] = ch[i]; 104 i--; 105 } 106 ch[j++] = '_'; 107 ch[j++] = 'n'; 108 ch[j++] = 'e'; 109 ch[j++] = 'w'; 110 } 111 112 void strname(char * filename, char * name, double version) { 113 int i = 0; 114 int j = 0; 115 int k = 0; 116 int l = 0; 117 int m = 0; 118 char ch; 119 char num[10]; 120 ch = filename[i]; 121 while (ch && ch != '.') 122 { 123 name[i] = ch; 124 ch = filename[++i]; 125 } 126 j = i; 127 i -= 4; 128 double vd = version - (int)version; 129 int vi = version; 130 name[i++] = '_'; 131 if (vi == 0) 132 name[i++] = '0'; 133 while (vi > 0) 134 { 135 k = vi % 10; 136 num[m++] = k + '0'; 137 vi /= 10; 138 } 139 while (m > 0) 140 name[i++] = num[--m]; 141 name[i++] = '_'; 142 k = vd * 10; 143 name[i++] = k + '0'; 144 vd = vd * 10 - k; 145 k = vd * 10; 146 name[i++] = k + '0'; 147 while (ch) 148 { 149 name[i++] = ch; 150 ch = filename[++j]; 151 } 152 name[i] = 0; 153 } 154 155 void cat(char * p, char * q, char * r) { 156 int i = 0, j = 0; 157 while (p[i]) 158 r[i++] = p[i]; 159 r[i++] = '\\'; 160 while (q[j]) 161 r[i++] = q[j++]; 162 r[i] = 0; 163 }