0

Hi,

I'm making a program that is has to send texts from textboxes to a external device wich shows them on leds.

But the LED's cant show every character(takes to much time :P), so i'm tasked to make a filter on the textboxes to check if they contain any invalid chars.

I have tried some things but i jsut cant figure out how to do this (I'm working in Visual Studio C++).

Thx,
DmD

2
Contributors
3
Replies
5
Views
10 Years
Discussion Span
Last Post by Ancient Dragon
0

you need to post your code that does not work. One way to do it is use strpbrk() function

char text[] = "Hello World";
// filter out 'H' and 'W' letters
char filter[] = "HW";

char *p = strpbrk(text,filter);
// if p == NULL then text[] does not contain any characters
// in filter[]
0

i got up with this kind of filter aswell but i need to filter characters that are *NOT* in an array, cos i cant go type all the characters that are in Windows....
(i only want to display:
abcdefghijklmnopqrstuvwxyz <space> 0123456789 . _ - ! ? + :
not:
öË@#*&|} etc.
)
thx

0
char filter[] = "abcdefghijklmnopqrstuvwxyz  0123456789 . _ - ! ? + :";
char text[] = "abcöË@#*&|}";

char buf[255] = {0};
char *ptr1 = buf;
char *ptr2 = text;
for(int i = 0; text[i] != 0; i++)
{
  // if the ith character in text is contained in filter
  // then add it to buf array.
  if( strchr(filter,text[i] != 0)
       *ptr1++ = text[i];
}
// now buf contains all the valid characters
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.