/*Write a C program that uses functions to perform
ii.) To Delete a string in to given main string from a Given position.*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void string_deletion(char[100]); /*FUNCTION DECLARATION*/
main()
{
char ms[100];
int i;
clrscr();
printf("Enter Main String:");
scanf("%s",ms);
printf("Main string and its position:\n");
for(i=0;ms[i]!='\0';i++)
printf("%c ",ms[i]);
printf("\n");
for(i=0;ms[i]!='\0';i++)
printf("%d ",i);
string_deletion(ms); /*FUNCTION CALLING BY PASSING THE VALUES*/
getch();
}
void string_deletion(char ms[100]) /*FUNCTION DEFINITION*/
{
int position,s1,i,n;
printf("\n Enter number of charaters your want to remove:");
scanf("%d",&n);
printf("Enter the position:");
scanf("%d",&position);
s1=strlen(ms);
if(position<0||position>s1)
printf("\nInvalid position........!");
else
{
for(i=position+n;i<=s1;i++)
ms[i-n]=ms[i];
printf("After Deletion %s",ms);
}
}
output:
Enter Main String:
MAHESHBABU
Main string and its position:
M A H E S H B A B U
0 1 2 3 4 5 6 7 8 9
Enter number of charaters your want to remove:4
Enter the position:6
After Deletion MAHESH
0 comments:
Post a Comment