Here i writing a function named void_RemoveAllChars() and is used for removing
all matching characters from the given string.
void RemoveAllChars(char*,char)
First argument is a string
Second argument is a character
Eg:
In the below example shows how to removing all the 'l' characters from the
string "llHello, world!ll".
Output:
all matching characters from the given string.
void RemoveAllChars(char*,char)
First argument is a string
Second argument is a character
Eg:
In the below example shows how to removing all the 'l' characters from the
string "llHello, world!ll".
#include <stdio.h>
void RemoveAllChars(char* String,char CharForRemoval)
{
char *Read = String, *Write = String;
while (*Read)
{
*Write = *Read++;
Write += (*Write != CharForRemoval);
}
*Write = '\0';
}
int main(int argc, char *argv[])
{
char str[]="llHello, world!ll";
RemoveAllChars(str,"l");
printf("Output is %s",str);
return 0;
}
void RemoveAllChars(char* String,char CharForRemoval)
{
char *Read = String, *Write = String;
while (*Read)
{
*Write = *Read++;
Write += (*Write != CharForRemoval);
}
*Write = '\0';
}
int main(int argc, char *argv[])
{
char str[]="llHello, world!ll";
RemoveAllChars(str,"l");
printf("Output is %s",str);
return 0;
}
Output:
"Heo, word!"
No comments:
Post a Comment