Thursday 11 April 2013

Program for character stuffing

import java.util.*;
class Char
{
    public static void main(String r[])
    {   
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter number of characters: ");
        int n=sc.nextInt();
        String in[]=new String[n];
        for(int i=0;i<n;i++)
        {
            in[i]=sc.next();
        }
        for(int i= 0;i<n;i++)
        {
            if(in[i].equals("dle"))
            {
                in[i]="dle dle";
            }
        }
        System.out.println("Transmitted message is: ");
        System.out.print(" dle stx ");
        for(int i=0;i<n;i++)
        {
            System.out.print(in[i]+" ");
        }
        System.out.println(" dle etx ");
    }
}


Example:
Sample output:
Enter number of characters:
5
a b dle dle d e
Transmitted message is:
dle stxa b dle dle dle dle d dle etx

Program to concatinate two strings


Program to concatinate two strings in C

void main()
{
char a[]={"Hello"}; //declare first char array
char b[]={"Everyone"}; //declare second char array
char c[50];
int n,i,j,k=0;
clrscr();
n=sizeof(a)+sizeof(b)-2; //store the total size of both array
for(i=0;i<sizeof(a);i++) //storing first array in the resultant array
c[i]=a[i];
for(i=sizeof(a)-1;i<n;i++,k++) //storing the second array in the resultant array
c[i]=b[k];
for(i=0;i<n;i++)
printf("%c",c[i]); //displat the result
getch();
}

Monday 8 April 2013

New Page added "ASK"



In this page u can ask any question or query or code related to any of the programming language which may be of C,C++,JAVA.
The solution will be posted on the blog as soon as possible...
So don't hesitate and ask anything u want......

visit http://rrprograms.blogspot.in/p/blog-page.html