Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: prob reading in a pnm file

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2002
    Posts
    2

    prob reading in a pnm file

    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!

    -dave

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2002
    Location
    Las Rozas, Madrid, Spain
    Posts
    4

    Re: prob reading in a pnm file

    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".

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2002
    Posts
    2

    Re: prob reading in a pnm file

    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?

  4. #4
    Junior Member Regular Contributor
    Join Date
    Nov 2001
    Location
    Malaysia
    Posts
    112

    Re: prob reading in a pnm file

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •