Thread: General Protection Exception

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    1

    Exclamation General Protection Exception

    I encountered this message (General Protection Exception) after I attempted to write into a text file. I cannot find anything wrong with it, and it works on another application (my friend's - it's almost the same).

    This is the error I got:
    General Protection Exception
    0x5677:0x48A2
    BOOKSHOP[1]0x48A2 Processor Fault

    If I execute this program again, the memory address will be different. I know GPE is about the pointer pointing into a memory that doesn't belong to me but I don't know what to do.

    This is how my program looks like. It's not very complicated, just a few classes, inheritance and I made an array of objects to store the data temporarily. Upon loading of the program I load the contents of the text file into the array and during runtime all manipulation will be made to the array in the memory. Upon exit, the program copies all data in the array into the text file.
    Code:
    //--------------------------------------------------------------------------------------------------------------------
    class MainApp{
    OFormStu ofArray[];
    RecForm rfArray[];
    Book bkArray[];
    UserAccount useracc[];
    
    public:
    MainApp();
    void loading();
    void get_choice();
    void enquiry();
    void bookorderform();
    void delbookorderform();
    void recform();
    void delrecform();
    void newbook();
    void destroybook();
    void useraccount();
    void adduseraccount();
    void moduseraccount();
    void remuseraccount();
    void login();
    void writefile();
    
    };
    MainApp::MainApp()
    {
    int c;
    OFormStu of;
    RecForm rf;
    Book bk;
    UserAccount ua;
    
    for(c=0; c<=MAX-1; c++)
    {
    ofArray[c]=of;
    rfArray[c]=rf;
    bkArray[c]=bk;
    useracc[c]=ua;
    }
    }
    
    void MainApp::loading()
    {
    FILE* fptr;
    int bisbn;
    char btitle[11];
    float bprice;
    char bdesc[31];
    int sid;
    char sname[11];
    int lid;
    char lname[11];
    int id;
    char name[11];
    char upass[11];
    int c;
    
    fptr=fopen("a:OrderFormStudent.txt","a+");
    c=0;
    if (!(fptr==NULL))
    {
    while (!feof(fptr))
    {
    fscanf(fptr,"%d",sid);
    
    /*if(feof(fptr))
    break;*/
    
    fscanf(fptr,"%s",sname);
    fscanf(fptr,"%d",bisbn);
    fscanf(fptr,"%s",btitle);
    fscanf(fptr,"%f",bprice);
    fscanf(fptr,"%s",bdesc);
    
    ofArray[c].setId(sid);
    ofArray[c].setName(sname);
    ofArray[c].setIsbn(bisbn);
    ofArray[c].setTitle(btitle);
    ofArray[c].setPrice(bprice);
    ofArray[c].setDesc(bdesc);
    c++;
    };
    }
    fclose(fptr);
    
    fptr=fopen("a:book.txt","a+");
    c=0;
    if (!(fptr==NULL))
    {
    while (!feof(fptr))
    {
    fscanf(fptr,"%d",bisbn);
    
    /*if(feof(fptr))
    break; */
    
    fscanf(fptr,"%s",btitle);
    fscanf(fptr,"%f",bprice);
    fscanf(fptr,"%s",bdesc);
    
    bkArray[c].setIsbn(bisbn);
    bkArray[c].setTitle(btitle);
    bkArray[c].setPrice(bprice);
    bkArray[c].setDesc(bdesc);
    c++;
    };
    }
    fclose(fptr);
    
    fptr=fopen("a:recform.txt","a+");
    c=0;
    if (!(fptr==NULL))
    {
    while (!feof(fptr))
    {
    fscanf(fptr,"%d",lid);
    
    /*if(feof(fptr))
    break;*/
    
    fscanf(fptr,"%s",lname);
    fscanf(fptr,"%d",bisbn);
    fscanf(fptr,"%s",btitle);
    fscanf(fptr,"%f",bprice);
    fscanf(fptr,"%s",bdesc);
    
    rfArray[c].setId(lid);
    rfArray[c].setName(lname);
    rfArray[c].setTitle(btitle);
    rfArray[c].setPrice(bprice);
    rfArray[c].setDesc(bdesc);
    c++;
    };
    }
    fclose(fptr);
    
    fptr=fopen("a:useraccount.txt","a+");
    c=0;
    if (!(fptr==NULL))
    {
    while (!feof(fptr))
    {
    fscanf(fptr,"%d",id);
    
    /*if(feof(fptr))
    break;*/
    
    fscanf(fptr,"%s",name);
    fscanf(fptr,"%s",upass);
    
    useracc[c].setId(id);
    useracc[c].setName(name);
    useracc[c].setPassword(upass);
    c++;
    };
    }
    fclose(fptr);
    }
    
    //--------------------------------------------------------------------------------------------------------------------
    void MainApp::writefile(){
    int c;
    FILE* fptr;
    
    fptr=fopen("a:book.txt","w+t");
    c=0;
    do
    {
    if (strcmp(bkArray[c].getTitle(),"A")==0)
    {c=c+1;}
    else
    {
    fprintf(fptr,"%d\n",bkArray[c].getIsbn());
    fprintf(fptr,"%s\n",bkArray[c].getTitle());
    fprintf(fptr,"%f\n",bkArray[c].getPrice());
    fprintf(fptr,"%s\n",bkArray[c].getDesc());
    c++;
    }
    }while(c <= MAX-1 && !feof(fptr));
    fclose(fptr);
    
    fptr=fopen("a:OrderFormStudent.txt","w+t");
    c=0;
    do
    {
    if (strcmp(ofArray[c].getName(),"U")==0)
    {c=c+1;}
    else
    {
    fprintf(fptr,"%d\n",ofArray[c].getId());
    fprintf(fptr,"%s\n",ofArray[c].getName());
    fprintf(fptr,"%d\n",ofArray[c].getIsbn());
    fprintf(fptr,"%s\n",ofArray[c].getTitle());
    fprintf(fptr,"%f\n",ofArray[c].getPrice());
    fprintf(fptr,"%s\n",ofArray[c].getDesc());
    c++;
    }
    }while(c <= MAX-1 && !feof(fptr));
    fclose(fptr);
    
    fptr=fopen("a:recform.txt","w+t");
    c=0;
    do
    {
    if (strcmp(rfArray[c].getName(),"U")==0)
    {c=c+1;}
    else
    {
    fprintf(fptr,"%d\n",rfArray[c].getId());
    fprintf(fptr,"%s\n",rfArray[c].getName());
    fprintf(fptr,"%d\n",rfArray[c].getIsbn());
    fprintf(fptr,"%s\n",rfArray[c].getTitle());
    fprintf(fptr,"%f\n",rfArray[c].getPrice());
    fprintf(fptr,"%s\n",rfArray[c].getDesc());
    c++;
    }
    }while(c <= MAX-1 && !feof(fptr));
    fclose(fptr);
    
    fptr=fopen("a:useraccount.txt","w+t");
    c=0;
    do
    {
    if (strcmp(useracc[c].getName(),"U")==0)
    {c=c+1;}
    else
    {
    fprintf(fptr,"%d\n",useracc[c].getId());
    fprintf(fptr,"%s\n",useracc[c].getName());
    fprintf(fptr,"%s\n",useracc[c].getPassword());
    c++;
    }
    }while(c <= MAX-1 && !feof(fptr));
    fclose(fptr);
    
    }
    //--------------------------------------------------------------------------------------------------------------------
    These are just snippets of my program, and probably the ones causing the problem, as they're the only methods in which I used pointers. Both are in MainApp class, among other methods that manipulates the array, as aforementioned.

    Please, can anyone help me? Thanks in advance.
    Last edited by s9uare; 11-02-2002 at 10:33 AM.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    See this:

    Code:
    OFormStu ofArray[];
    RecForm rfArray[];
    Book bkArray[];
    UserAccount useracc[];
    The compiler is obligated to allocate a single object for each of these arrays. They need sizes, else make them pointers and allocate the sizes at runtime...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A general protection exception failure
    By louis_mine in forum C Programming
    Replies: 7
    Last Post: 11-25-2004, 02:22 AM
  2. Please assistance, general protection mistake
    By louis_mine in forum C++ Programming
    Replies: 3
    Last Post: 10-23-2004, 10:45 PM
  3. General Protection?
    By drdroid in forum C++ Programming
    Replies: 1
    Last Post: 08-17-2002, 10:09 AM
  4. general protection exception
    By chiw in forum C Programming
    Replies: 1
    Last Post: 08-14-2002, 09:54 AM
  5. General protection exception??
    By jonesy in forum C Programming
    Replies: 6
    Last Post: 10-10-2001, 12:34 AM