/* Write a C program that uses functions to perform the following operation:To delete n Characters from a given position in a given string.
*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char a[100], b[100];
int i,j,n;
int p;
clrscr();
printf("\n Enter the String of Charecters");
gets(a);
Printf("\n Enter the position from where the string has to be deleted");
scanf("%d",&p);
printf("\n Enter the no. of charecters you want to delete");
scanf("%d",&n);
r=strlen(a);
if((n+p)>r)
{
printf("\n End of String reached");
printf("\n Please enter a valid no. of charecters..");
}
for(i=0;i<r;i++);
{
b[i]=a[i];
}
for(i=p;i<r;i++)
{
b[i]='\0';
}
/* or
int c[100]
for(i=0;i<p-1;i++)
c[i]=b[i];
*/
printf("\n The String after deleting the substring is");
printf("%s",b);
/*printf("%s",c);*/
getch();
}
*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char a[100], b[100];
int i,j,n;
int p;
clrscr();
printf("\n Enter the String of Charecters");
gets(a);
Printf("\n Enter the position from where the string has to be deleted");
scanf("%d",&p);
printf("\n Enter the no. of charecters you want to delete");
scanf("%d",&n);
r=strlen(a);
if((n+p)>r)
{
printf("\n End of String reached");
printf("\n Please enter a valid no. of charecters..");
}
for(i=0;i<r;i++);
{
b[i]=a[i];
}
for(i=p;i<r;i++)
{
b[i]='\0';
}
/* or
int c[100]
for(i=0;i<p-1;i++)
c[i]=b[i];
*/
printf("\n The String after deleting the substring is");
printf("%s",b);
/*printf("%s",c);*/
getch();
}
No comments:
Post a Comment