DELETE A NO.OF CHARACTERS FROM STRING - C-Tutorial

Latest

Monday, 26 September 2016

DELETE A NO.OF CHARACTERS FROM STRING

/* DELETE A NO.OF CHARACTERS FROM STRING */


#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char str[20];
int i,n,pos,len;
clrscr();
printf("\n\n Enter a string: ");
gets(str);
printf("\n\n Enter a no.of characters to delete: ");
scanf("%d",&n);
printf("\n\n Enter a position from delete a charcters: ");
scanf("%d",&pos);
len=strlen(str);
if(pos-1>len)
printf("\n\n Deletion is not possible ");
else
for(i=pos;i<len;i++)
{
str[i]=str[i+n];
}
printf("\n\n After delete %d characters the given string is: \n",n);
puts(str);
getch();
}

No comments:

Post a Comment