title: How to get a string from a string (char pointer in C)
body: <p>The question is simple but the C language doesn't provide us with a useful library:</p>
  
  <p>Suppose that we have this string:</p>
  
  <pre><code>char *request  = "GET /websiteos/example_of_a_simple_html_page.htm HTTP/1.1\r\n";
  </code></pre>
  
  <p>How can I get the following string:</p>
  
  <blockquote>
    <p>/websiteos/example_of_a_simple_html_page.htm</p>
  </blockquote>
  
  <p>The string I’m looking for is found between 2 spaces. The problem is that each time I will have a new request line, so I don't know the size of the string.</p>
  
  <p>I thought I'd proceed like this, but it doesn't work:</p>
  
  <pre><code>char * getTheResource(char *request){
  char c;
  int i=4;
  char *resource=(char *)malloc(20);
  while   (request[i] != ' ')
  {   strcat(resource, request[i]);
      i++;
  }
  return resource;
  
  }
  
  int main( int n , char *arg[] )
  {   
      char *request  = "GET /websiteos/example_of_a_simple_html_page.htm HTTP/1.1\r\nHost: help.websiteos.com\r\n\r\n";
      char *res =getTheResource(request);
      printf("the ressource is :%s\n",res);
  }
  </code></pre>
  
  <p>I'm getting a compilation error:</p>
  
  <blockquote>
    <p>In function ‘getTheResource’:<br>
    example.c:19:3: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [enabled by default]<br>
       strcat(resource, request[i]);</p>
  </blockquote>
  
  <p>So how can I solve this problem?</p>