C Programming code for Deleting Elements from Strings – KLETech

Write a Modular C Programming Code for Deleting Elements from Strings | Sentence?

CODE:

#include<stdio.h>
#include<string.h>
void DELETE(char str[],int position, int length);
main()
{
char str[100];
int position, length;
printf("Enter the string\n");
scanf("%s",str);
printf("From which position the characters of a string should be deleted\n");
scanf("%d",&position);
printf("How many character should be deleted from %d position\n",position);
scanf("%d",&length);
DELETE(str,position,length);
printf("String after deletion of characters = %s\n",str);
}
void DELETE(char str[],int position, int length)
{
int i=0;
int j =0;
char target[100];
while(i<position-1)
{
target[j]=str[i];
i++;
j++;
}
i = i + length;
while(str[i]!='\0')
{
target[j]=str[i];
i++;
j++;
}
target[j]='\0';
strcpy(str,target);
}

 

OUTPUT

Enter the string
123456789
From which position the characters of a string should be deleted
2
How many character should be deleted from 2 position
3
String after deletion of characters = 156789

Process returned 0 (0x0) execution time : 11.548 s
Press any key to continue.

 

Please find some more codes of 1D Arrays, 2D Arrays, Pointers on the below page:

Top 100+ C Programming codes – KLE Technological University

 







Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

Welcome to FactsPrime

Sorry, We have detected that you have activated Ad-Blocker. Please Consider supporting us by disabling your Ad Blocker, It helps us in maintaining this website. To View the content, Please disable adblocker and refresh the page.

Thank You !!!