P160. To delete a character from the string using strcpy & strchr user defined functions
#include<stdio.h>
void
my_print(const char *);
void
my_strcpy(char *,char *);
const
char *my_strchr(const char *,char);
void
main()
{
char c[30],ch;
const char *cp;
printf("Enter the string :
");
scanf("%s",c);
printf("Enter a character :
");
scanf(" %c",&ch);
while(cp=my_strchr(c,ch))
my_strcpy(cp+1,cp);
my_print(c);
}
const
char *my_strchr(const char *p,char ch)
{
while(*p)
{
if(*p==ch)
return p;
p++;
}
return 0;
}
void
my_strcpy(char *p,char *q)
{
while(*q)
{
*q=*p;
p++;
q++;
}
}
void
my_print(const char *p)
{
while(*p)
{
printf("%c",*p);
p++;
}
printf("\n");
}
Comments
Post a Comment