2015-10-08 36 views
1

嗨我有问题打印前锋'/'在我的html文件,我需要从选择输入收集数据,并将值发送到我的.cgi文件,但是当我选择一个值,如“/ home”,它打印“ %2Fhome“我如何解决这个问题?感谢乌拉圭回合的答案..如何在C中打印前端?

Shell: <select name=shell> 
    <option value="/bin/bash">/bin/bash</option> 
    <option value="/bin/sh">/bin/sh</option> 
    <option value="/usr/bin/csh">/usr/bin/csh</option> 
    <option value="/bin/false">/bin/false</option> 
    </select><br> 
+1

HTTP POST数据是URL编码,它取代特殊字符%后跟一个十六进制代码。您应该使用CGI库来解码它。 – Barmar

回答

1

下面的代码读取并打印到终端传递的文件。测试你的文字。

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

int main(int argc, char *argv[]) 
{ 
    FILE *fd; 

    if (argc < 2) 
    { 
     return EXIT_FAILURE; 
    } 

    // Open requested file 
    fd = fopen(argv[1], "rb"); 

    // Check file opened 
    if (fd == NULL) 
    { 
     // Couldn't open file 
     return EXIT_FAILURE; 
    } 

    // Step through the file until EOF occurs 
    int c; 
    while ((c = fgetc(fd)) != EOF) { 
     printf("%c", c); 
    } 

    // Close file 
    fclose(fd); 

    return EXIT_SUCCESS; 
} 

与命令编译它:gcc -o test test.c -Wall -std=c99

然后调用它为:./test test.txt