Encoders
  Home  Forum  Guestbook  Email Us  About Us  Links  More Hub for Computer Whizzes Register to join us

C
C++
Security
Miscellaneous
Encoders > More... > C > Program 21

<< Previous  Next >>


/* Function escape(s,t) that converts characters like newline and tab into
   visible escape sequences like \n and \t. */

#include <stdio.h>

void escape(char s[], char t[]);

main()
{
        char a[50], b[]="hello\tworld\n";
	escape(a,b);
        printf("%s\n",a);
}

void escape(char s[], char t[])
{
	int i,j;
	for(i=0,j=0;t[j]!='\0';i++,j++)
		switch(t[j])
		{
			case '\t': case '\n':
				s[i++]='\\';
				s[i]=t[j]=='\t' ? 't' : 'n';
				break;
			default:
				s[i]=t[j];
		}
	s[i]='\0';
}

 

encoders.20m.com - hosted at 20m.com
Site design and development by Susam Pal
-----------------------------------------------------