Simple CGI Programming in C

CK CK 3788 
Created at  
545 0 0
Here's the simplest C based CGI example.


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

int main(void)
{
    char *data;

    printf("Content-Type:text/html;xdxa"); // HTML out start !!

    printf("<TITLE>Multiplication results</TITLE> ");
    printf("<H3>Multiplication results</H3> ");

    data = getenv("QUERY_STRING"); // getting parameters

    if(data == NULL)
      printf("<P>No Query string found");
    else
      printf("<P>%s", data);

    return 0;
}


If you want to run this application on Apache platform, you can test this application by copying to Apache cgi-bin directory.

If it's compiled as test.exe and installed in Apache installed local PC, you can test it by following URL:

http://127.0.0.1/cgi-bin/test.exe



http://127.0.0.1/cgi-bin/test.exe?helloworld

Tags C++ CGI CGI Example CGI Sample MFC CGI Example QUERY_STRING getenv Facebook X
Comments 0
Similar posts
  1. C++ CGI Example working on Apache
    483
  2. Simple C# CGI working on Apache
    480
  3. Fast and Good Keyboard/Mouse Test without the message handler
    982
  4. How to send binary data through C# CGI app?
    994
  5. Creating and Using a CAsyncSocket Object to use CAsyncSocket
    472
  6. MFC based World Wide Web HTTP Server Source Code
    459
  7. Double Linked List based in C++
    796
  8. Binary Search Sample Code
    404
  9. How to run shell command by MFC ?
    435
  10. How to get Referral URL ?
    2,077
  11. How to search file on certain directory ?
    629
  12. How to call SetTimer function on MFC CDialog class ?
    650
  13. Makefile to automate the build process for C++
    279
  14. How to load HTML resource on MFC ?
    841
  15. URL Encode, Decode function for MFC
    604
  16. KMP String Matching Algorithm
    672
  1. Double Linked List based in C++
    796
  2. String Replace Function For C#
    1,547
  3. How to print character in C# by ASCII code
    476
  4. MFC based World Wide Web HTTP Server Source Code
    459
  5. Creating and Using a CAsyncSocket Object to use CAsyncSocket
    472
  6. UDP Send and Receive Using CAsyncSocket
    1,204
  7. Using the shell to receive notification of removable media being inserted or removed
    680
  8. Adding Custom Paper Sizes To Named Printers
    646
  9. Print HTML In C# With Or Without The Web Browser Control And The Print Dialog
    972
  10. A Customizable Printing Text Class
    432
  11. Simplified .NET Printing In C#
    692
  12. How To Print Text In C#
    455
  13. C# Lists
    1,151
  14. Simple Example of IF/THEN using C#
    1,265
  15. Fast and Good Keyboard/Mouse Test without the message handler
    982
  16. C++ CGI Example working on Apache
    483
  17. Simple C# CGI working on Apache
    480
  18. How to send binary data through C# CGI app?
    994
  19. Interacting With TinyPic From C#
    1,303
  20. Creating A Watched Folder With Assigned Events
    1,658
  21. Calling Your Main Thread From A Worker Thread In C#
    546
  22. HashTable Tutorial In C#
    1,787
  23. Stack Tutorial In C#
    668
  24. Queue Tutorial In C#
    1,737
  25. Create PDF Files On the Fly in C#
    1,002
  26. How to call Visual C/C++ implemented DLL functions in C# - Simple DLLImport
    1,160
  27. Send Email Using C#
    1,377
  28. How To Read And Write A Cookie
    363
  29. Using C# With Cookies
    625
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    39
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    34
  3. How do I create animated background for Google Meet?
    20,611
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    244
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    94
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    157
  7. Array of arguments passed to script in PHP
    90
  8. Invalid Auction Storms in Ad Tech
    98
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    202
  10. The Two Clocks of Ad Server Architecture
    70
  11. Frequency Cap Architecture Overview
    514
  12. Collecting Proof-of-Play from 100,000 Screens
    146
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    287
  14. What is RedisVL?
    109
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    230
  16. TPU & GPU Cluster Management Tools
    243
  17. The Concept of Scaffolding in AI Agents
    233
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    583
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    258
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    339
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    202
  22. Machine Learning: Training vs. Ranking
    221
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    222
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    195
  25. Designing a Data Curation System Around a Vector Database
    220
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    256
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    656
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    195
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    216
  30. Understanding Data Lineage
    260