I'm trying to pass string as filename. I wonder if there is some smart function checking every character of string if it's alphanumeric, or belongs to group of few other character specified?
Loop on every string character seems not very efficient for this. Any ideas?

I'm afraid that, even if you found some function in some library somewhere, it's implementation would still be O(n) (where n is the number of characters)....After all, a string is just an array of characters, and so you would have to see each character to determine if it is a digit or a number (or has an ASCII value within a certain range...)

EDIT: the only way I could think of improving this is to preprocess the data, which I don't think is practical for you purpose...Of course, if you are reading in a filename (from a user say), then you could check the characters as they are read, thereby avoiding an extra glance at the entire array...