PDA

View Full Version : prob reading in a pnm file



mitzman
01-13-2002, 02:10 PM
so i have a win32 program that is supposed to make a rotating cube and put a picture that i specify on the faces of the cube. the picture is in pnm (ppm) format. the program worked great in linux. problem is in windows it will compile but not run! the error i get is

"DEBUG assertion failed!"
program: e:\cube\debug\cube.exe
file: fscanf.c
line: 54

Expression: stream != null

i don't know what to do. can't find an answer. here's the code from the main function...

int main(int argc, char **argv) {
FILE *fd;
int k, nm;
char c;
int i;
char b[70];
float s;
int red, green, blue;

printf("enter file name: ");
scanf("%s", b);
fd = fopen("bill.pnm", "r");
fscanf(fd, "%[^\n]", b);
if (b[0] != 'P'| | b[1] != '3') {
printf("%s is not a PPM file!\n", b);
exit(0);
}

fscanf(fd, "%c", &c);
fscanf(fd, "%c", &c);
fscanf(fd, "%c", &c);
fscanf(fd, "%c", &c);
fscanf(fd, "%c", &c);
fscanf(fd, "%c", &c);

while (c == '#') {
fscanf(fd, "%[^\n]", b);
fscanf(fd, "%c", &c);
}

ungetc(c, fd);
fscanf(fd, "%d %d %d", &n, &m, &k);

printf("%d rows %d columns max value = %d\n", n, m, k);

nm = n*m;

image = malloc(3*sizeof(GLuint)*nm);

s = 255./k;

for(i = 0; i <nm; i++) {
fscanf(fd, "%d %d %d", &red, &green, &blue);
image[3*nm - 3*i - 3] = red;
image[3*nm - 3*i - 2] = green;
image[3*nm - 3*i - 1] = blue;
}

glPixelTransferf(GL_RED_SCALE, s);
glPixelTransferf(GL_GREEN_SCALE, s);
glPixelTransferf(GL_BLUE_SCALE, s);

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(n, m);
glutInitWindowPosition(0, 0);
glutCreateWindow("image");
glutReshapeFunc(myreshape);
glutDisplayFunc(display);
glutIdleFunc(spincube);
init();


glutMainLoop();
}


if you need more let me know! http://www.opengl.org/discussion_boards/ubb/smile.gif

-dave

Neko
01-14-2002, 08:27 AM
Originally posted by mitzman:

scanf("%s", b);
fd = fopen("bill.pnm", "r");
fscanf(fd, "%[^\n]", b);
if (b[0] != 'P'| | b[1] != '3') {
printf("%s is not a PPM file!\n", b);



I don't know if it was a test, but the file name used with fopen should be "b".

mitzman
01-14-2002, 09:42 AM
yeah that was just a test, shouldn't matter though. there has to be an alternative to using fscanf but i don't know what it is. any ideas?

Questions Burner
01-16-2002, 03:17 AM
I think your file is not succesfully opened.
Because the file pointer will be NULL if it's not succesfully opened. That's why the assertion:

stream != null

failed. Try:

if(fd == NULL)
{
printf("Cannot open file\n");
exit(0);
}

Hope this helps.