Skip to content

Instantly share code, notes, and snippets.

@robbkidd
Created September 21, 2012 22:37
Show Gist options
  • Save robbkidd/3764326 to your computer and use it in GitHub Desktop.
Save robbkidd/3764326 to your computer and use it in GitHub Desktop.
Escaping things
#include <stdio.h>
#include <string>
#include <string.h>
int main() {
std::string str = "ab:cd:ef";
const char *psz = str.c_str();
for (;;)
{
const char *pszNext = strpbrk(psz, ":");
if (!pszNext)
{
printf("%s", psz);
break;
}
printf("%.*s\\%c", pszNext - psz, psz, *pszNext);
psz = pszNext + 1;
}
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment