Mailing List Archive



Back to the month index Back to the list index

David Sklar (sklar@student.net)
Tue, 1 Apr 1997 13:54:27 -0500 (EST)


Date: Tue, 1 Apr 1997 13:54:27 -0500 (EST)
From: David Sklar <sklar@student.net>
Subject: [mSQL] answer: escaping chars in C
Message-Id: <Pine.LNX.3.95.970401135337.5502E-100000@juan-epstein.student.net>

ok, i answered my own question. here's the code I'm using...
-dave
 http://www.student.net

--------
#define CHARS_TO_ESCAPE "'\\"
char *msqlEscape(char *pcOld) {
  char *pcNew = NULL;
  int iOld = 0, iNew = 0;

  pcNew = (char *) malloc(2*strlen(pcOld));

  while(iOld < strlen(pcOld)) {
    if (strchr(CHARS_TO_ESCAPE, pcOld[iOld]))
      pcNew[iNew++] = '\\';
    pcNew[iNew++] = pcOld[iOld++];
  }

  pcNew[iNew] = '\0';
  pcNew = realloc(pcNew,strlen(pcNew));
  return(pcNew);
}
----------

--------------------------------------------------------------------------
To remove yourself from the Mini SQL mailing list send a message containing
"unsubscribe" to "unsubscribe" to msql-list-request@bunyip.com. Send a message containing
"info msql-list" to majordomo@bunyip.com for info on monthly archives of
the list. For more help, mail owner-msql-list@bunyip.com NOT the msql-list!