
cat crap | autoescape

Void Main wrote:EDIT: I'm not sure what you mean by "special characters". I thought you meant "non-printable" chars but I see you have "^" and "*" which are printable. "special chars" in what context? Different chars are considered special depending on what you mean. I guess I need to see the bigger picture of what you are getting at.
I hate to get bits and pieces only to work out a very complex solution for something that was very simple in the first place.

#include <stdio.h>
int main() {
char c;
while ((c = getchar ()) != EOF) {
switch (c) {
case '!' : case '@' : case '#' : case '$' : case '%' : case '^' : case '&' :
case '*' : case '(' : case ')' : case '-' : case '_' : case '=' : case '+' :
case '\\': case '|' : case '`' : case '~' : case '\'': case '\"': case '/' :
case '?' : case '.' : case '>' : case ',' : case '<' :
printf("\\%c",c);
break;
default: printf("%c",c);
}
}
}
#include <stdio.h>
int main() {
char c;
char str[] = "!@#$%^&*()-_=+|`~""/?.>,<";
while ((c = getchar ()) != EOF) {
if (strchr(str,c)) printf("\\%c",c);
else printf("%c",c);
}
}

sed 's/\([!@#$%^&*()_=+|`~"/?.>,<]\)/\\\1/g'
$ echo "Hmm... &This might work! Maybe?" | sed 's/\([!@#$%^&*()_=+|\`~"/?.>,<]\)/\\\1/g'
Hmm\.\.\. \&This might work\! Maybe\?

Users browsing this forum: No registered users and 1 guest