Getting colors with printf, C, Xcode, MacOs ?

I need to print texts in various colors, with a program in C under Xcode 10.3 and OSX 10.14.6

With

printf(" Black, \033[31m Red ");

what is printed is all black, and is

Black, [31m Red.

The same with "033" replaced by "e"

Any solution?

Help much appreciated

Replies

Are you running your tool from Xcode? Or in Terminal? Xcode’s console does not support ANSI escape codes, so this is not expected to work there. It does, however, work just fine in Terminal.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks.

As said, I use Xcode.

Not familiar with running C with Terminal under Macos => I will look at it.

As said, I use Xcode.

Indeed, but there’s a difference between using Xcode to build your tool and using Xcode to run it.

Not familiar with running C with Terminal

You can still build the tool with Xcode, you just have to run it from Terminal. You’ll probably want to disable your colour generation when run from Xcode, so you get colours when deploying to Terminal but don’t see this noise when you’re debugging with Xcode.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"