To print the octal values of non-printable characters if printable then print the characters itself.

#include <stdio.h>
#include <ctype.h>
#define MAXSIZE 100
main()
{
char ch[MAXSIZE];
int character,i=0; /* character is taken as int bcuse of EOF which is -1 */
system("clear");
do
{
character=getchar();
ch[i++]=character;
}
while(character!=EOF);

ch[--i]='';     /* EOF is replaced by NULL */

printf("\n");
i=0;
while(ch[i]!='')
{
if(isprint(ch[i])) /* isprint available in std., library */
printf("%c",ch[i]);
else
printf(" \%o ",ch[i]);
i++;
}
printf("\n");
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s