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.

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>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.