Input stored to the string, and then judged one by one, remove illegal characters can be.
I. Algorithm analysis:
1, input string.
2, one by one to determine whether it is legal, if not, then delete. Deletion method can use subsequent characters to overwrite the current character.
3, can be traversed from front to back, each illegal character is covered by subsequent legal characters, so that a cycle can complete all operations.?
Second, the reference code:
#include?<stdio.h>int?main()
{
char?s[100];
char?*p,? *q;
gets(s);// Input string.
for(p=q=s;*p!='\0';?p++)//Iterate through the string with the p pointer.
if((*p>='0'? &&? *p<='9')? ||? (*p>='a'? &&? *p<='f')||(*p>='A'? &&? *p<='F'))//Legal hexadecimal characters.
*q++=*p;//assign to the corresponding position.? Only legal ones are assigned, so that illegal ones are overwritten.
*q='\0';//Add new string terminator.
printf("%s\n",?s);//Output the result.
return?0;
}