fscanf_s needs work

Discussion in 'Software' started by longbowrocks, Apr 17, 2010.

  1. longbowrocks

    longbowrocks Private E-2

    I'm trying to use fscanf_s and fgetc to read an OBJ file, but when I debug I get the error:
    Unhandled exception at 0xfefefefe in Final Project.exe: 0xC0000005:
    Access violation reading location 0xfefefefe.
    I imagine this is a problem with my error handling for fscanf_s, but I feel I may be running into problems soon. I'm posting this in advance while I work on it to see if anyone gets a solution before me. Here's the relevant code.

    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream>
    #include "HeliParser.h"

    #define BUFFER 100

    namespace cole_parser{

    void parse(){
    FILE* fp = NULL;
    try{
    int except = fopen_s(&fp, "cube.obj", "r");
    if(fp == NULL || except){
    throw 0;
    }
    }
    catch(int exception){
    printf("program failed\n");
    exit(exception);
    }
    char b[BUFFER]; // buffer

    do{
    fscanf_s(fp, "%s", b, BUFFER);
    if(b[0] == '#'){// This line is commented; kill it.
    #if DEBUG 1
    printf("comment here\n");
    #endif
    kill_ln(fp);
    }else if(b == "mtllib"){// This line names the material library; kill it for now.
    kill_ln(fp);
    }else if(b[0] == 'v'){// This line defines a vertex; store it.
    }else if(b == "usemtl"){// This line names the material in use; kill it for now.
    kill_ln(fp);
    }else if(b[0] == 's'){// This line would set a smoothing group, but it's no longer in use; kill line.
    kill_ln(fp);
    }else if(b[0] == 'f'){// This line defines a face; store it.
    }
    }while(b[0] != EOF);

    fclose(fp);
    }

    void kill_ln(FILE* fp){
    char discard; // Character to check if end of file or end of line has been reached
    do{
    discard = fgetc(fp);
    }while(discard != '\n' && discard != EOF);
    }
    }
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds