1 #define _CRT_SECURE_NO_WARNINGS
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <time.h>
5
6 void main()
7 {
8 //显示html文本
9 printf("Cotent-type:text/html\n\n");
10 //获取表单信息
11 char szpost[256] = { 0 };
12 gets(szpost);
13 //输出表单信息
14 printf("%s", szpost);
15
16 //对表单信息进行处理,把'+'转换成' '
17 char *pstart = szpost;
18 for(int i=0;i<256;i++)
19 {
20 if (szpost[i] == '+')
21 {
22 szpost[i] = ' ';
23 }
24 }
25
26 //处理':'号
27 char *pos1 = strstr(szpost, "%3A");
28 if (pos1 != NULL)
29 {
30 *pos1 = ':';
31 *(pos1 + 1) = ' ';
32 *(pos1 + 2) = ' ';
33 }
34
35 //处理'\'
36 pos1 = strstr(szpost, "%2F");
37 if (pos1 != NULL)
38 {
39 *pos1 = '\\';
40 *(pos1 + 1) = ' ';
41 *(pos1 + 2) = ' ';
42 }
43
44 //获取第一个输入框的内容
45 char *p1 = strchr(szpost, '&');
46 if (*p1 != NULL)
47 {
48 *p1 = '\0';
49 }
50 //输出第一个输入框的内容
51 printf("%s\r\n", szpost+5);
52
53 //获取第二个输入框的内容
54 char *p2 = strchr(p1 + 1, '&');
55 if (*p2 != NULL)
56 {
57 *p2 = '\0';
58 }
59 //输出第二个输入框的内容
60 printf("%s\r\n",p1+6);
61
62 //整合成cmd指令
63 char cmd[256] = { 0 };
64 //生成随机数,写入到随机数文件中
65 time_t ts;
66 unsigned data = time(&ts);
67 srand(&ts);
68 int num = rand();
69
70 //整合cmd指令,并重定向到文件
71 sprintf(cmd, "%s %s >%d.txt", szpost + 5, p1 + 6, num);
72 //文件名
73 char filename[100] = { 0 };
74 //生成文件名
75 sprintf(filename,"%d.txt", num);
76 //执行指令
77 system(cmd);
78 //打开文件
79 FILE *pf = fopen(filename,"r");
80 //读取文件
81 while (!feof(pf))
82 {
83 char ch = fgetc(pf);
84 putchar(ch);
85 }
86 //关闭文件
87 fclose(pf);
88 }