fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void) {
  5. char *url = "http://w...content-available-to-author-only...e.com/hello.html";
  6. // find the last index of `/`
  7. char *path = url + strlen(url);
  8. while (path != url && *path != '/') {
  9. path--;
  10. }
  11. int hostLen = path-url;
  12. char *hostName = malloc(hostLen+1);
  13. memcpy(hostName, url, hostLen);
  14. hostName[hostLen] = '\0';
  15. printf("%s\n%s\n", path, hostName);
  16. free(hostName);
  17. return 0;
  18. }
Success #stdin #stdout 0s 1920KB
stdin
Standard input is empty
stdout
/hello.html
http://w...content-available-to-author-only...e.com