You are printing one more pixel for each row (the last row of each color prints 200 pixels more).
Change
for (i = 0; i <= width; i++) {
to
for (i = 0; i < width; i++) {
EDIT:
but how come I can say "<=" for the height?
for (j = 0; j < heightWhite; j++) = 0...199 = 200 items
for (j = 1; j <= heightWhite; j++) = 1...200 = 200 items
Note that all your code can be executed with two loops:
#include <stdio.h>
int main(void)
{
int width = 800, height = 600, icolor = 0, i, j;
unsigned char color[][3] = {
{255, 255, 255}, /* white */
{0, 0, 255}, /* blue */
{255, 0, 0} /* red */
};
printf("P6\n");
printf("%d %d\n", width, height);
printf("255\n");
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
printf("%c%c%c", color[icolor][0], color[icolor][1], color[icolor][2]);
}
if (i && (i % 200 == 0)) icolor++; /* 200, 400, 600 */
}
return 0;
}