Question: Missing some lines of code. Purple version is the professors. White is mine, tried writing code to show the debug name_value_pairs but it wont compile
Missing some lines of code. Purple version is the professors. White is mine, tried writing code to show the debug name_value_pairs but it wont compile


#include
#include
#include
#include
#include
using namespace std;
struct FIELDS
{
string name;
string value;
};
const int cnt = 3;
// Prototypes
void parse(string, FIELDS []);
string param(string, FIELDS [], int);
//main begins
int main()
{
FIELDS name_value_pairs [cnt], f_name_value_pairs[2];
string qs(getenv("QUERY_STRING"));
//string qs("first=fred&last=flint&color=red");
cout "Content-type:text/html ";
cout "debug with qs: " qs " " endl; parse(qs, name_value_pairs); string first = param("first", name_value_pairs, cnt); string last = param("last", name_value_pairs, cnt); string color = param("color", name_value_pairs, cnt); // these values were not declared. So, now you have to enter their values string fred, flint, red; cout"Enter value of fred : "; cin>>fred; cout"Enter value of flint : "; cin>>flint; cout"Enter value of red : "; cin>>red; f_name_value_pairs [0].name = first; f_name_value_pairs [0].value = fred; f_name_value_pairs [1].name = last; f_name_value_pairs [1].value = flint; f_name_value_pairs [2].name = color; f_name_value_pairs [0].value = red; cout " first: " first " cout " last: " last " cout " color: " color " return 0; } //******************************************* //******** Functions begin ****************** //******************************************* void parse (string qs, FIELDS f_name_value_pairs []) { 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; f_name_value_pairs[counter].name = name; start_pos = pos + 1; pos = qs.find("&", start_pos); if (pos == string::npos) { pos = qs.length(); } value = qs.substr(start_pos, pos - start_pos); cout "value: " value " " endl; f_name_value_pairs[counter].value = value; 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 i=0; if_cnt; i++) { if (lookUp == f_name_value_pairs[i].name) { return f_name_value_pairs[i].value; } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
