#include <stdio.h>
char strip_off_chars(char *str)
{
int cnt = 0;
char *ptr = str;
while(*ptr)
{
if(*ptr >= '0' && *ptr <= '9')
{
cnt++;
str[cnt - 1] = *ptr;
}
ptr++;
}
str[cnt] = '\0';
return;
}
int main()
{
char str1[] = "Jagadish1234";
char str2[] = "1234Jagadish";
char str3[] = "jaga1234dish";
char str4[] = "ja1ga2di3sh4";
char str5[] = "jaga12dish34";
char str6[] = "j1a2g3a4d5i6s7h8";
char str7[] = "1234";
strip_off_chars(str1);
printf("The stripped string is %s\n", str1);
strip_off_chars(str2);
printf("The stripped string is %s\n", str2);
strip_off_chars(str3);
printf("The stripped string is %s\n", str3);
strip_off_chars(str4);
printf("The stripped string is %s\n", str4);
strip_off_chars(str5);
printf("The stripped string is %s\n", str5);
strip_off_chars(str6);
printf("The stripped string is %s\n", str6);
strip_off_chars(str7);
printf("The stripped string is %s\n", str7);
}
OutPut:
The stripped string is 1234
The stripped string is 1234
The stripped string is 1234
The stripped string is 1234
The stripped string is 1234
The stripped string is 12345678
The stripped string is 1234