Richard
Richard

Reputation: 21

Any other way to print on the screen instead of printf() and fprintf() in C?

I'm programming with gcc in CentOS 5.5 and the most of time I use printf() and fprintf() to print on terminal, but in some websites I've seen that some people use write(). I want to know if there's other ways to print on terminal.

Thanks.

Upvotes: 0

Views: 4132

Answers (3)

Jonathan Leffler
Jonathan Leffler

Reputation: 753675

All the output functions in the C standard I/O library could be used:

Most of the other write-like functions in POSIX could be used (but a few are reserved for sockets and those probably can't be used).

There are many functions in the curses library that could be used.

Upvotes: 1

Yu Hao
Yu Hao

Reputation: 122383

There are some major differences between these functions.

  1. The standard library provides some functions to output to stdout: printf, puts, putchar etc.
  2. And some functions to output to a stream, you can specify the stream to stdout: fprintf, fputs, fwrite, etc.
  3. But write is different, it's a low-level I/O function. The standard library doesn't provide any low-level I/O functions. For example, POSIX provides write that can output to a file descriptor.

Google for how to use each one of them.

Upvotes: 2

shanet
shanet

Reputation: 7324

You could use puts() or putchar().

puts("Hello, world!\n");

There's a also fputs(), putc(), and fputc() if you want/need to specify a FILE* to write to.

Upvotes: 1

Related Questions