"joe" <jc*****@gmail.comwrote in message
hello i have a databse program that uses char arrays to output data to
reports. I would like to remove all invalid characters from the array
and replace them with a blank space. I have problems with ( ' return
and some non ascii charcters. Any quick and dirty way to do this?
thanks.
Why do it quick and dirty when a decent program only takes a minute?
/*
must a character be repalced by a space?
Params: ch - character to test
Returns: 1 if must be replaced, 0 if must be retained
*/
int replaceme(char ch)
{
if(isalnum(ch))
return 0;
if(isspace(ch))
{
if(ch == '\n' || ch == '\t')
return 0;
else
return 1;
}
/* other conditions here for punctuation and so on */
}
/*
This might need a substantial rewrite if you wish to distinguish gibberish
from a name which might have
one or two European or punctuation characters embedded in it, eg O'Rourke,
Bronte with two dots over the e, and so forth.
*/
void fixstring(char *str)
{
while(*str)
{
if(replaceme(*str))
*str = ' ';
str++;
}
}
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm