#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>


int main(void)
{
  CURL *curl_handle;
  CURL *curl;
  FILE *fp;
  fp = fopen("received.txt","w");
  CURLcode res;
  int fd[2],er, pid;
  //char  *a;    //not working

  er = pipe(fd);
  if(er == -1)
    printf("\n*************************************\nerror while creating the pipe\n");
  else
    printf("\n*************************************\nSuccessfully created pipe\n");

  pid = fork();

  if(pid == 0)
  {
     //  close(fd[1]);              not working
     //  read(fd[0], a, 11);
     //  fprintf(fp, "%s", a);
    //fclose(fp);
    curl = curl_easy_init();
 

 /**********working as called after curl_easy_init()********************/
      char *a;
      close(fd[1]);
      read(fd[0], a, 11);
       fprintf(fp, "%s", a);
      fclose(fp)    ;
/*****************************************************************/

if (curl) {
      curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080");
      res = curl_easy_perform(curl); // perform a POST request
      if(res != CURLE_OK)
        fprintf(stderr, "curl_easy_perform() failed: %s\n",
                curl_easy_strerror(res));

      curl_easy_cleanup(curl);

      curl_global_cleanup();
    }
  }

  else{
    close(fd[0]);
    write(fd[1],"he am here",11);
  }
  return 0;
}
