public
Created

Escaping things

  • Download Gist
gistfile1.c
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#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;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.