Is it possible to use a function to detect non-printing characters with isctrl()
and use printf with %C specifier to print them as '\n' for instance?
Or I should write an if
for every control caracter and printf("\\n")
for instance..?
OK, thanks to All of the kind people below - it is not posible, you HAVE to specify each situation. example:
if (isctrl(char))// WRONG
printf("%c", char);
if (char == '\n')//RIGHT, or using switch.
printf("\\n");
To show non-printing characters in Word, click the “Home” tab in the Ribbon. Then click the “Show/Hide Non-Printing Characters” button in the “Paragraph” button group.
Non-printable characters are parts of a character set that do not represent a written symbol or part of the text within a document or code, but rather are there in the context of signal and control in character encoding.
Answer: This is Ctrl+* (Ctrl+Shift+8 on U.S. keyboards). If you've ever turned on display of nonprinting characters unintentionally, it may have been by accidentally pressing this key combination when you were trying to type an asterisk.
const char *pstr = "this \t has \v control \n characters";
char *str = pstr;
while(*str){
switch(*str){
case '\v': printf("\\v");break;
case '\n': printf("\\n"); break;
case '\t': printf("\\t"); break;
...
default: putchar(*str);break;
}
str++;
}
this will print the non-printable characters.
To expand on the answer by Aniket, you could use a combination of isprint
and the switch-statement solution:
char ch = ...;
if (isprint(ch))
fputc(ch, stdout); /* Printable character, print it directly */
else
{
switch (ch)
{
case '\n':
printf("\\n");
break;
...
default:
/* A character we don't know, print it's hexadecimal value */
printf("\\x%02x", ch);
break;
}
}
You can determine the non-printing character, but i dont think so, you can write those characters. You can detect specific non printing characters by observing their ASCII value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With