Program to delete n Characters from a given position in a given string using functions

This C program uses function delchar to delete n characters from a given position in a given string.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "stdio.h"
#include "conio.h"
#include "string.h"
 
void delchar(char *x,int a, int b);
 
void main()
{
     char string[10];
     int n,pos,p;
     clrscr();
 
     puts("Enter the string");
     gets(string);
     printf("Enter the position from where 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);
    }
}
Chitra
Chitra

One thought on “Program to delete n Characters from a given position in a given string using functions

  1. this is not program…………………………………………………………………………………………………………………………

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in