Aim:
To insert a substring into a string.
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[80],newstr[80];
int pos,len,count1=0,
int i=0,t=0 ;
clrscr ();
printf("Enter a string:");
gets(str);
while( str[i] != '\0' )
{
count1++;
i++;
}
printf("\nEnter the position to delete the characters:");
scanf("%d",&pos);
printf("\nEnter the number characters to delete:");
scanf("%d",&len);
t = pos;
for( i=pos+len;i<=count1-len;i++)
{
str[t] = substr[i];
t = t+1;
}
printf("\nNewstring is: %s",str);
}
Program:
Enter a string: hyabundai
Enter the position to delete the characters: 3
Enter the number of characters to delete : 2
Newstring is: hyundai
No comments:
Post a Comment