Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
getenv(QUERY_STRING) Returning NULL

I am currently trying to make a simple CGI Program that outputs someone's input in C. Oddly, the environment variable "QUERY_STRING" is returning null. Here is the code that I have, two simple files, one being a .html, and one being a .c.

simple.c

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

void openHTML(char* path);
int main(){
        printf("Content-Type: text/html \n\n");
        openHTML("simple.html");
        char* data;
        data = getenv("QUERY_STRING");
        printf("Data: %s", data);
        return 0;

}

void openHTML(char* path){
        //Opens File
        FILE* file = fopen(path, "r");
        //Reads through lines
        char line[256];

        while (fgets(line, sizeof(line), file)) {

                printf("%s", line);
        }

        fclose(file);

}

simple.html

<html>
        <body>

                <form action="http://localhost/cgi-bin/simple.exe" method="post">
                        <label for="fname">First name:</label>
                        <input type="text" id="fname" name="fname"><br><br>
                        <label for="lname">Last name:</label>
                        <input type="text" id="lname" name="lname"><br><br>
                        <input type="submit" value="Submit">
                </form>
        </body>
</html>

Current output:

Content-Type: text/html

<html>
        <body>

                <form action="http://localhost/cgi-bin/simple.exe" method="post">
                        <label for="fname">First name:</label>
                        <input type="text" id="fname" name="fname"><br><br>
                        <label for="lname">Last name:</label>
                        <input type="text" id="lname" name="lname"><br><br>
                        <input type="submit" value="Submit">
                </form>
        </body>
</html>
Data: (null)
over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda