簡體   English   中英

如何在C中打印斜線?

[英]How to print frontslash in C?

嗨,我在html文件上打印反斜杠'/'時遇到問題,我需要從選擇的輸入中收集數據並將值發送到我的.cgi文件,但是當我選擇“ / home”之類的值時,它將打印“%2Fhome我該如何解決? 感謝您的答復。

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>

下面的代碼讀取並打印以終止所傳遞的文件。 測試您的文字。

#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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM