/* Write a C program to delete n Characters from a given position in a given string.
*/
include
include
include
void delchar(char *x,int a, int b);
main()
{
char string[10];
int n,pos,p;
//clrscr();
puts("Enter a string :");
gets(string);
printf("Enter the position from where you want to delete:");
scanf("%d",&pos);
printf("Enter the number of characters to be deleted :");
scanf("%d",&n);
delchar(string, n,pos);
getch();
}
// Function to delete n characters
void delchar(char *x,int a, int b)
{
if ((a+b-1) <= strlen(x))
{
strcpy(&x[b-1],&x[a+b-1]);
puts(x);
}
}
OUTPUT:
Enter a string :
programming9
Enter the position from where you want to delete:6
Enter the number of characters to be deleted :5
progrg9