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

Recommended Answers

All 3 Replies

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[]

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

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.