Thread: Request QueryString Value for CGI style app

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2004
    Location
    London
    Posts
    12

    Request QueryString Value for CGI style app

    Hello All,

    I'm hoping this is not a stupid question but I am quite new to C, so If it is dumb, please humour me.

    I am trying to write a function for use in my CGI style app.

    The function is to return the value of the specified item in the QUERY_STRING environment variable. If the item does not exist it returns a blank string "".

    This is what I have done but not working how I thought it would.

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
     
    int main(){
     printf(QueryString("test"));
    }
     
    // ---- Return QueryString Value ---- //
    QueryString(char *strobj){
     char *qs = getenv("QUERY_STRING");
     char *init_word;
     if (qs){
            if (strstr(qs, strobj)){
       char *word;
       char *strtype = "name";
       char *stropt = "false";
       word = strtok(qs, "&,=");
       while (word){
        if (strcmp(word, strobj)){
         if (strtype == "name"){
          stropt = "true";
         }
         else{
          if (stropt == "true"){
           return word;
           break;
          }
         }
        }
        if (strtype == "name"){
         strtype = "value";
        }
        else{
         strtype = "name";
        }
        word = strtok(NULL, "&,=");
       }
      }
      else{
       return "";
      }
     }
     else{
            return "";
     }
    }
    Could someone please give me a helping hand.

    Also does anyone know of any good C CGI tutorials?

    Thanks and any help is much appreciated.

    Kind Regards,
    Tarran
    Last edited by Tarran; 12-29-2004 at 02:59 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Controls Style: Resource View vs Running App
    By devGordon in forum Windows Programming
    Replies: 4
    Last Post: 06-19-2009, 09:43 PM
  2. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  3. Instant messenger app help
    By AusTex in forum C Programming
    Replies: 2
    Last Post: 05-01-2005, 12:41 AM
  4. best program to start
    By gooddevil in forum Networking/Device Communication
    Replies: 4
    Last Post: 05-28-2004, 05:56 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM