Saturday, March 23, 2013

C Language Example # 44 Merge String at nth position of main string (Method 2)

C Language Example # 44 Merge String at nth position of main string (Method 2).

* This program demonstrate addition of one string into another one at specific position.

//Written by : Latest Technology Guide
//Title : C Language Example # 44 Merge String at nth position of main string (Method 2)..

 
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
    clrscr();
    int i,n,j=0;
    char str[70],addstr[50];

    printf("Enter the String :");
    gets(str);

    printf("Enter New String to Enter : ");
    gets(addstr);

    printf("Enter Position At : ");
    scanf("%d",&n);

    j=strlen(addstr);

    for(i=n;i<strlen(str)-j;i++)
    {
        str[i]=str[i+j];
    }
    str[i]=NULL;

    puts(str);
    printf("New Strlen() is : %3d",strlen(str));

    getch();
}


Output:
* Program will merge string and will display the new string.


--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 44 Merge String at nth position of main string (Method 2).

* You need to enter 3 input. input 1 main string, input 2 : sub string and input 3 : value of n where you want to copy your sub string into main string.
* Program will find that nth position and will copy sub string into main one.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.

No comments:

Post a Comment