#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
void Result (char *result, char string, char remove);
char *RemoveChars( char *src
, char *key );
int main(void)
{
char string[] = "Alesia";
char remove[] = "aeiou";
char result;
Result (&result, string, remove);
fflush(stdin);
printf(" Press any key ...\n");
getchar();
return 0;
}
void Result (char *result, char string, char remove)
{
*result = NULL;
result = RemoveChars( string
, remove );
printf( "The result is %s\n", result );
}
char *RemoveChars( char *src, char *key )
{
char *dest;
int found;
int i,j,k;
i = 0;
j = 0;
k = 0;
dest = NULL;
dest = (char *) malloc( sizeof( char ) * strlen( src ) + 1 );
memset( dest, 0x00, sizeof( char ) * strlen( src ) + 1 );
for ( i = 0; i < strlen( src ); i++ ) {
found = FALSE;
for ( j = 0; j < strlen( key ); j++ ){
if ( src[i] == key[j] )
found = TRUE;
}
if ( FALSE == found ) {
dest[k++] = src[i];
}
}
return ( dest );
}
First of all, i am appoogize because this topic has been posted but
1. im trying to call the removechar function with another function but it doesnt work.
2. is there any other way that doesnt require the use of malloc in removechar function that easier to understand?
Im new to C so simple explaination is best for me
thanks for all your help and have a nice day. :)