title: Get input from cgi POST data
body: <p>This is my c++ code to retrieve html data with cgi. </p>
  
  <pre><code>char* fileContentLength;
  int nContentLength;
  fileContentLength = getenv("CONTENT_LENGTH");
  
  if(fileContentLength == NULL)   
      return -1;      
  
  nContentLength = atoi(fileContentLength);   
  
  if(nContentLength == 0) 
      return -1;
  
  data = (char*) malloc(nContentLength+1);
  
  if(data == NULL)    
      return -1;
  
  memset(data, 0, nContentLength+1);  
  if(fread(data, 1, nContentLength, stdin) == 0)  
      return -1;
  
  if(ferror(stdin))
  </code></pre>
  
  <p>After executing this code, i got the below result to the variable "data".</p>
  
  <blockquote>
    <p>f0=fname0&amp;l0=lname0&amp;f1=fname1&amp;l1=lname1&amp;f2=fname2&amp;l2=lname2&amp;f3=&amp;l3=</p>
  </blockquote>
  
  <p>Here f0,l0,f1,l1 are name of the input box of the HTML page. From this string i need to separate the values like fname0, lname0,fname1,lname1 and so on. I used sscanf function. but i could not retrieve the correct result. How can i assign the values from the above string to a local variable called firstname and lastname.</p>