I'm writing to a .ppm file, so far I'm just testing it by writing 0 and 1 to it. When I open the file in Notepad, the numbers show up as symbols. But when I open it up in WordPad or Microsoft Word the numbers appear. Surely there's nothing wrong with the code and it's Notepad's fault? I've tried to find out via Google but I can't find anything. Essentially, what I'm doing is expanding a file that contains values like, (1 1 1 1) to (1 0 0 1 0 0 1 0 0 1 0 0) which are the red pixels and then adding green and blue values in the same manner.
I get ‱‰‰‱‰‰‱‰‰‱‰‰, instead of 100100100100.
The code is:
#include <stdio.h>
int redArray[128][256 * 3];
int main(void) {
int x;
int y;
FILE *redFile = NULL;
imagePixels = fopen("image.ppm", "w");
redFile = fopen("image.red", "r");
readRed(redFile);
for (y = 0; y < 128; y++) {
for (x = 0; x < 256 * 3; x += 3) {
redArray[y][x] = 1;
}
}
for (y = 0; y < 1; y++) {
for (x = 0; x < 256 * 3; x++) {
fprintf(imagePixels, "%d ", redArray[y][x]);
}
}
fclose(redFile);
fclose(imagePixels);
return 0;
}
// This function is in a different .c file. I completely forgot to add it here but I'll leave at the '#include' business.
void readRed(FILE *colourFile) {
for (y = 0; y < 128; y++) {
for (x = 0; x < 256; x++) {
fscanf(redFile, "%d", &redArray[y][x]);
}
}
}