title: Dynamically choose which #define to reference
body: <p>I am writing an HTTP 1.0 downloader and using these #define replacements to format the query:</p>
  
  <pre><code>#define GET_FORMAT "GET %s%s HTTP/1.0\r\nHost: %s\r\nUser-Agent: getter\r\n\r\n"
  #define HEAD_FORMAT "HEAD %s%s HTTP/1.0\r\nHost: %s\r\nUser-Agent: getter\r\n\r\n"
  #define GET_FORMAT_RANGE "GET %s%s HTTP/1.0\r\nHost: %s\r\nRange: %s\r\nUser-Agent: getter\r\n\r\n"
  #define HEAD_FORMAT_RANGE "HEAD %s%s HTTP/1.0\r\nHost: %s\r\nRange: %s\r\nUser-Agent: getter\r\n\r\n"
  </code></pre>
  
  <p>Im using something like this currently to replace the '%s' parts of the query string. I feel it could be more graceful:</p>
  
  <pre><code>char* query_string_formatter(char* page, char* host, int get){ 
      switch(get) {
          case 0:
          //HEAD
          {
              char* query = malloc(strlen(host) + strlen(page) + 1 + HEAD_FORMAT_LEN);
              if (page[0] == '/') {
                  sprintf(query,HEAD_FORMAT, "", page, host);
              } else { 
                  sprintf(query, HEAD_FORMAT, "/", page, host);
              }
              return query;
          }
          default: 
          //GET
          {
              char* query = malloc(strlen(host) + strlen(page) + 1 + GET_FORMAT_LEN);
              if (page[0] == '/') {
                  sprintf(query,GET_FORMAT, "", page, host);
              } else { 
                  sprintf(query, GET_FORMAT, "/", page, host);
              }
              return query;
          }
      }
  
  }
  </code></pre>
  
  <p>But id love to replace it with something more graceful kind of like this:</p>
  
  <pre><code>...
  
  sprintf(query, format, "",page,host);
  </code></pre>
  
  <p>Where format is either GET or HEAD, instead of having several nested if statements and repetitious code</p>