fork download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5.  
  6. int main(int argc, char **argv) {
  7. char str[] = "Foo: bar\n"; /* you have the header already */
  8. size_t len = strlen(str); /* and it's length */
  9.  
  10. char *split = strchr(str, ':');
  11.  
  12. if (split) {
  13. char *key = malloc(split - str + 1);
  14.  
  15. memcpy(key, str, split - str);
  16.  
  17. key[split - str] = 0;
  18.  
  19. printf("First: %s\n", key);
  20.  
  21. char *value = malloc(len - (split - str) + 1);
  22.  
  23. memcpy(value, &str[split - str + 1], len - (split - str));
  24.  
  25. value[len - (split - str)] = 0;
  26.  
  27. printf("Second: %s\n", value);
  28. }
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
First: Foo
Second:  bar