隨筆-40  評(píng)論-66  文章-0  trackbacks-0
          啥都不說(shuō),直接看代碼!

          簡(jiǎn)單輸出代碼

          #include <stdio.h>
          #include <stdlib.h>
          #include <string.h>
          void main()
          {
          printf("Content-type:text/html\n\n");

          printf("hello world!");

          fflush(stdout);

          }



          處理get代碼

          #include <stdio.h>
          #include <stdlib.h>
          int zmain(void)
          {char *data;
          long m,n;
          printf("%s%c%c\n","Content-Type:text/html;charset=iso-8859-1",13,10);
          printf("<TITLE>Multiplication results</TITLE>\n");
          printf("<H3>Multiplication results</H3>\n");
          data = getenv("QUERY_STRING");
          if(data == NULL) 
          printf("<P>Error! Error in passing data from form to script.");
          else if(sscanf(data,"m=%ld&n=%ld",&m,&n)!=2) 
          printf("<P>Error! Invalid data. Data must be numeric.");
          else 
          printf("<P>The product of %ld and %ld is %ld.",m,n,m*n);
          return 0;
          }


          處理post代碼

          #include<stdio.h>
          #include<stdlib.h>
          void main()
          {
           int i,n;
           printf("Content-type:text/html\n\n");
           n=0;
           if(getenv("CONTENT_LENGTH"))
            n=atoi(getenv("CONTENT_LENGTH"));
           printf("%d",n);
           for(i=0;i<n;i++)
            putchar(getchar());
           putchar('\n');
           fflush(stdout);
          }



          還是代碼


          #include <stdio.h>
          #include <stdlib.h>
          #include <string.h>

          /* 轉(zhuǎn)換函數(shù)聲明 */
          int htoi(char *);

          /*  主函數(shù) */
          void zmain() {
           int i,n;
           char c;
           printf ("Content-type: text/html\n\n");
           n=0;
           if (getenv("CONTENT_LENGTH"))
            n=atoi(getenv("CONTENT_LENGTH"));
           for (i=0; i<n;i++){
            
            int is_eq=0; //判斷是否有等于號(hào)。
            
            c=getchar();
            switch(c){
            case '&':
             c='\n';
             break;
            case '+':
             c='+';
             break;
            case '%':
             {
              char s[3];
              s[0]=getchar();
              s[1]=getchar();
              s[2]=0;
              c=htoi(s);
              i+=2;
             }
             break;
            case '=':
             c='=';
             is_eq=1;
             break;
            };
            
            putchar(c);
            //if (is_eq) putchar(' ');
           }
           putchar ('\n');
           fflush(stdout);
          }

          /* 轉(zhuǎn)換為小寫 */
          int islower (int ch ) 

          {
              return (unsigned int) (ch - 'a') < 26u;
          }


          /* convert hex string to int 16進(jìn)制轉(zhuǎn)換成10進(jìn)制 */
          int htoi(char *s)

          {
           
           char *digits="0123456789ABCDEF";
           
           if(islower(s[0])) s[0]=toupper(s[0]);
           if(islower(s[1])) s[1]=toupper(s[1]);
           
           return 16 * (strchr(digits, s[0]) -strchr(digits,'0') ) +(strchr(digits,s[1])-strchr(digits,'0'));
           
          }


          #include<stdio.h>
          #include<stdlib.h>
          void zzzmain()
          {
           int i,n;
           printf("Content-type:text/html\n\n");
           n=0;
           if(getenv("CONTENT_LENGTH"))
            n=atoi(getenv("CONTENT_LENGTH"));
           printf("%d",n);
           for(i=0;i<n;i++)
            putchar(getchar());
           putchar('\n');
           fflush(stdout);
          }

           

          posted on 2008-02-26 15:37 Super·shen BLOG 閱讀(751) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 穆棱市| 长垣县| 双辽市| 珠海市| 新兴县| 余庆县| 原平市| 乌拉特后旗| 临江市| 莎车县| 玉林市| 深泽县| 安仁县| 江津市| 措勤县| 陵川县| 通化县| 福安市| 黑山县| 拜泉县| 乌拉特中旗| 克什克腾旗| 华安县| 扎鲁特旗| 故城县| 中卫市| 阿坝县| 永州市| 林口县| 比如县| 恩施市| 北宁市| 汉源县| 兰考县| 清涧县| 宜阳县| 马尔康县| 尚志市| 濮阳县| 易门县| 武功县|