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