program that converts characters like newline, blank and tab into visible sequence like \n, \b and \t


#include < stdio.h>
#include< conio.h>
#include< string.h>
void main()
{
char str1[100],str2[100];
int i=0,j=0;
clrscr();
printf("Enter the string with blanks,tabs and new line\n");
printf("At the end put full stop.\n");
gets(str1);
while(str1[i]!='.')
{
switch(str1[i])
{
case ' ':
{
str2[j]=';';
j++;
str2[j]='b';
j++;
i++;
break;
}
case '\t':
{
str2[j]=';';
j++;
str2[j]='t';
j++;
i++;
break;
}
case '\n':
{
str2[j]=';';
j++;
str2[j]='n';
j++;
i++;
break;
}
default :
{
str2[j]=str1[i];
j++;
i++;
break;
}
}
}
str2[j]='\0';
for(i=0;i<=strlen(str2);i++)
{
if(str2[i]==';')
printf("\\");
else
printf("%c",str2[i]);
}
getch();
}





No comments:

Post a Comment