I am trying to print out the number of occurences for each alphabetic chracter in a file that our instructor provided us with. The values range from 1 to 999. I'm trying to print out "count[...] : " followed by the character. So far my counts are correct. However, at the end of each & every line, the program 'spits' out the digit '4.' Is the problem being caused by the arguments in my printf function? Thanks!

// The values of possible count[c] range from 1 through 999

// Print array of the 26 letters in the alphabet & their counts
for (c = 0 ; c < 26 ; c++)
     cout << "count['" << (char)('a' + c) << "'] : " << printf(" %3u", count[c]);
		cout <<  endl;

You really shouldn't mix cout and printf especially on the same line...When you have this

<<printf("whatever")

You'll print out the result of calling printf which is four characters in your code.

Edited 6 Years Ago by gerard4143: n/a

Mixing cout and printf to output your results is a mistake.

That 4 being output is the return value of printf, it printed 4 characters.

Get rid of the printf and instead pipe count[c] staight to cout in the normal way. If you want to format the output read up on the io manipulators found in the header <iomanip>

This question has already been answered. Start a new discussion instead.