im a newbie on programming, and i need to show a binary file in my program in the first phase.
with the help of my teacher, i was able to do that, but when i was working late in the code i change somethings that i couldn't get back now :(
this is the code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
FILE *f;
int a = 0, b = 0, c = 0, d = 0;
float cinzentos = 0, mlinha = 0, ppixeis = 0;
unsigned char matriz[28][28][500];
f = fopen("dados1.bin", "rb");
if (f != NULL) {
while (!feof(f)) {
b++;
if (b == 28) {
printf(" soma: %f ", mlinha);
printf(" cizentos: %f ", mlinha / 28);
printf("\n");
b = 0;
a++;
mlinha = 0;
printf("%d %d %d", a, b, c);
}
if (a == 28) {
a = 0;
c++;
ppixeis = (ppixeis / 28 * 28) * 0.1;
printf("media de pixeis: %f\n", ppixeis);
printf("\n---------------\n");
}
matriz[a][b][c] = fgetc(f);
if (matriz[a][b][c] != 0) {
printf("1");
mlinha = mlinha + matriz[a][b][c];
ppixeis++;
fputc(matriz[a][b][c], p);
} else {
printf("0");
}
}
}
fclose(f);
return 0;
}
I think, that's is because the file opening, but im in looping trying to put this back together , need help