Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I count the number of characters that are printed as output?

Tags:

c++

c

Does anyone know how I can print and count the number of characters that I printed?

Say I have a number I am printing via printf or cout. How could I count the actual number of digits I have printed out?

like image 765
Dave Powell Avatar asked Dec 01 '22 06:12

Dave Powell


2 Answers

According to the printf man page, printf returns the number of characters printed.

int count = printf("%d", 1000);

If an output error is encountered, a negative value is returned.

like image 169
jschmier Avatar answered Feb 14 '23 09:02

jschmier


printf returns the number of characters it printed

like image 36
Martin Beckett Avatar answered Feb 14 '23 11:02

Martin Beckett