I copied your program, made some changes, and it worked fine:

1. I compiled with gcc -Wall -Wextra roster.c and addressed all the diagnostics that gcc put out.

2. I added a 0.0 initializer for the average field in the struct initializers.

3. I changed the declaration of the temp array to 15 characters.

4. I added (void)argc; (void)argv; to main, to suppress the unused-argument warning (I assume you are actually using those parameters in your read-in-the-data-from-a-file variant of this program.

With those changes made, I got:

# First Last B H W RBI AVG
== ===== ==== == == == === ===
0 Joe Shmoe 3 1 0 0 .333
4 Shoeless Joe 5 1 1 1 .200
5 Joey Makrs 4 1 1 0 .250
7 Slim Jim 1 0 0 0 .000
18 Jay Hay 9 2 2 2 .222
Then I went back, changed the declaration of temp to just 5 characters again, and got results the same as yours.

Obviously, the size of the temp buffer makes a difference. Consider:

temp = [_, _, _, _, _];

sprintf("%0.3f", 0.123); // temp = [0, ., 1, 2, 3, NUL]; <-- 6 bytes!

Where does the 6th byte go? It goes into the next location on the stack!

What is stored at the next location on the stack? I have no idea!

Except that I do have an idea: it's probably the x variable!

Most, if not all, Intel CPU's are "little-endian". That is, they store multi-byte numbers with the least-significant bits in the lowest-addressed byte. The number 0x11223344 would be stored as bytes 0x44, 0x33, 0x22, 0x11 in that order.

More importantly, the number 0x00000001 would be stored as 0x01, 0x00, 0x00, 0x00.

And if something, like, say, sprintf, came along and wrote a 0x00 to the very first byte, it would replace the 0x01 and convert x from 0x00000001 back into 0x00000000.

So what might happen?

x = 0
sprintf writes the average to temp, plus a 0-byte to x, replacing 0x00000000 with 0x00000000 (no change).
the roster[x]'th player is printed out, with average = temp (0.333)
x += 1
sprintf writes the average to temp, plus a 0-byte to x, replacing 0x00000001 with 0x00000000 (1 -> 0)
x = 0 because of this
the roster[x]'th player is printed out, with average = temp (0.200)
x += 1 (again)
... etc ...