Question
so iam creating a code that will need to do some kind of little html coding with c++ . i am trying to make quiz
so iam creating a code that will need to do some kind of little html coding with c++ . i am trying to make quiz related to harry potter theme . which witch are you? i want each option to give a result of that characters gif that i want to use using url. i dont know how to go about coding . there are two codes that i have in my pico editor connect to a linux server.
first is web form html
and now this is the c++ coding
#include
struct FIELDS { string name; string value; };
const int cnt = 3; //cnt should be set to the number of fields the html form contains
// Prototypes void parse(string, FIELDS []); string param(string, FIELDS [], int);
//main begins int main() { FIELDS name_value_pairs [cnt];
string qs(getenv("QUERY_STRING")); //string qs("first=fred&last=flint&color=red"); cout << "Content-type:text/html "; cout<<"
"; cout << "debug with qs: " << qs << "" << endl;
parse(qs, name_value_pairs);
// debug to show content of name_value_pairs cout << "debug to show content of name_value_pairs array: " << endl << " "; for (int index = 0; index
// Three fields data are retrieved from the param function string first = param("first", name_value_pairs, cnt); string last = param("last", name_value_pairs, cnt); string Witch = param("Witch", name_value_pairs, cnt);
// code an HTML page, which includes the three fields // received.
cout<<" "; cout<<"
"; cout<<"Using a Full URL File Path
"; cout<<"Parameter Parser "; cout<<" "; cout<<" "; cout<<" first value="<cout<<" "; cout<<" "; // code an HTML page, which includes the three fields // received. cout<<" "; return 0;
}
//******************************************* //******** Functions begin ******************
/ parse() // This will separate the name/value pairs found after the ? in // the URL and populate the name_value_pairs array of structures //******************************************* void parse (string qs, FIELDS f_name_value_pairs []) { cout << "debug in parse " << endl; string name, value; int start_pos = 0, pos; for (int counter=0; counter < cnt; counter++) { pos = qs.find("=", start_pos); name = qs.substr(start_pos, pos - start_pos); cout << "name: " << name << " " << endl; start_pos = pos + 1; pos = qs.find("&", start_pos); if (pos == string::npos) { pos = qs.length(); } value = qs.substr(start_pos, pos - start_pos); f_name_value_pairs[counter].name=name; //store the name of current parameter in array f_name_value_pairs[counter].value=value; //store the value of current parameter in array start_pos = pos + 1; } }
//******************************************* // param() // This will find the field value based on the // field name //******************************************* string param(string lookUp, FIELDS f_name_value_pairs[], int f_cnt) { for(int counter=0; counter
"; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started