Isprint() not working on Linux (resolved: usage error)

Hi, I'm not sure if this is the right place to report this, but I think I found a case where isprint() is not working correctly on Linux. I tried digging into the code, but I don't quite understand where isprint() is defined. I did find a function in the swift compiler called isPrint() that appears to be reasonable, though. (fails on swift-5.2.4-RELEASE-ubuntu18.04, works on Apple Swift version 5.2.4)

isprint is part of libc.

https://linux.die.net/man/3/isprint

Yes, but how are C functions passed through to Swift? And why wouldn't isprint() work if it works in C?

What do you mean when you say that it doesn't work?

import Glibc

let c = Character("x")
print("\(isprint(Int32(c.asciiValue!)) != 0)")

I'm doing something similar:

let ch = data[ndx+startIndex]
if isprint(Int32(Int(ch))) == 1 {

Where "data" is a Data() object. It appears to be always returning false.

Don't forget that the man page says: "The values returned are nonzero if the character c falls into the tested class, and a zero value if not." (emphasis mine).

Ah that's a good point. I'll take a look at that.

That turns out to be it. Thanks!

Terms of Service

Privacy Policy

Cookie Policy