Thread: compiler error

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    14

    compiler error

    Hi

    I have tried to write 2 of 4 programs. Both i have finished, compiled with no errors or warnings. Problem arises when i run the programs or trace. I have a message:-

    General Protection Exception
    0x5C87:0x47B3
    program(1) 0x5C87:0x47B3 Processor Fault


    both programs have the same message, different numbers?
    There is also a linker error that occurs:

    No module definition file specified:using defaults.


    Any help in rectifing the problem would be appreciated.
    If you need to see the code give me a shout and i'll post it.
    The compiler is turboc++ 4.5 for windows


    Thanx

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    I have received errors similar to those before. IIRC they were easily solved. Could we see some code?
    The world is waiting. I must leave you now.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    14

    compiler code

    The program below compiled no errors/warnings. Yet when I trace, it gets past the opening of the files. Goes to the headings function gets past the first print line the stops with the general protection message on the second print line. It is the same for the first program. I think, therefor, a problem lies within the headings function?

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <conio.h>
    #include <math.h>
    #include <time.h>

    #define FILE_1 "rec_test.txt"
    #define FILE_2 "A:zencvf.dat"
    #define FILE_3 "sorted valid.dat"
    #define PRINT "printout"
    #define SPACES " "
    #define SIZE sizeof(union s_rec)
    #define MAXLINES 60
    #define VALID 1
    #define INVALID 0

    struct cust_i_r { // details of issue/return file
    char rec_type;
    char cust_code[6];
    char part_no[7];
    int quantity;
    };


    struct cust_del { // details of deletion file
    char rec_type;
    char cust_code[6];
    };

    struct cust_cre { // details of creation file
    char rec_type;
    char cust_code[6];
    char cust_name[21];
    char cust_addr[61];
    float cust_bal;
    long credit_limit;
    };


    union s_rec { // details of union
    struct cust_i_r iss;
    struct cust_del del;
    struct cust_cre cre;
    };

    struct tm todays_date;

    FILE *in_ptr;
    FILE *out_ptr;
    FILE *report_ptr;

    int lines = 0;
    int page_no =0;


    //function prototypes

    FILE *open_file(char *filename, char *mode);
    void p2_headings(void);
    void printout(union s_rec *ptr);
    void summary2(int c, int d, int i, int r, int t_rec, int c_tot);
    int compare(const void*a, const void*b);

    void main()
    {
    union s_rec *buf, *start, *move;
    int c_rec = 0, d_rec = 0;
    int i_rec = 0, r_rec = 0;
    int tot_recs = 0, tot_cust = 0;
    int i, num = 0;
    char code[6] = "00000";

    in_ptr = open_file(FILE_2 , "rb");
    out_ptr = open_file(FILE_3 , "wb");
    report_ptr = open_file(PRINT , "wb");


    p2_headings();
    lines+=7;


    while( (fread(&buf, SIZE, 1, in_ptr) ) == 1 )
    {
    num++;
    }

    start = (union s_rec*)malloc(num*SIZE);
    rewind(in_ptr);

    fread(start, SIZE*num, 1, in_ptr);

    qsort(start, num, SIZE, compare);

    fwrite(start, SIZE*num, 1, out_ptr);

    move = start;

    for(i=0; i<num; i++)
    {
    printout(move);
    switch(move->cre.rec_type)
    {
    case 'C':c_rec++;
    tot_recs++;
    if( strcmp(code, move->cre.cust_code) )
    {
    tot_cust++;
    strcpy(code, move->cre.cust_code);
    }
    break;
    case 'D':d_rec++;
    tot_recs++;
    if( strcmp(code, move->cre.cust_code) )
    {
    tot_cust++;
    strcpy(code, move->cre.cust_code);
    }
    break;
    case 'I':i_rec++;
    tot_recs++;
    if( strcmp(code, move->cre.cust_code) )
    {
    tot_cust++;
    strcpy(code, move->cre.cust_code);
    }
    break;
    case 'R':r_rec++;
    tot_recs++;
    if( strcmp(code, move->cre.cust_code) )
    {
    tot_cust++;
    strcpy(code, move->cre.cust_code);
    }
    break;
    }

    move++;
    }

    fclose(in_ptr);
    fclose(out_ptr);
    free(start);

    summary2(c_rec,d_rec,i_rec,r_rec,tot_recs,tot_cust );

    fclose(report_ptr);

    }


    FILE *open_file(char *filename, char *mode)
    {
    FILE *fp_ptr;

    if( (fp_ptr = fopen(filename,mode) ) == NULL)
    {
    clrscr();
    gotoxy(5,5);
    printf("Unable to open file:\t%s",filename);
    gotoxy(5,8);
    printf("program terminating.\t Press any key to continue.");
    getch();
    }
    return(fp_ptr);
    } /* end open_file() */


    void p2_headings(void)
    {


    fprintf(report_ptr,"\n%s%-63s%-27s %d/%d/%d%-10s %d\n\n",
    "ZENITH PAINTS",
    "TRANSACTION ACTIVITY REPORT",
    "DATE:",
    todays_date.tm_mday,
    todays_date.tm_mon+1,
    todays_date.tm_year-100,
    "PAGE:",
    page_no);
    fprintf(report_ptr,"\n%s%-6s%-7s%-6s%-94s%-10s\n",
    "REC","CUST",
    "PART","I/R"
    "CUSTOMER",
    "CREDIT");
    fprintf(report_ptr,"%s%-5s%-8s%-5s%-16s%-25s%-53s%-9s\n\n",
    "TYPE","CODE",
    "NUMBER","QTY",
    "CUSTOMER NAME",
    "CUSTOMER ADDRESS",
    "BALANCE","LIMIT");

    } /* end p2_headings() */


    void printout(union s_rec *ptr)
    {
    char temp_addr[61];
    char temp_name[21];

    if( lines >= (MAXLINES-14) )
    {
    fprintf(report_ptr,"\f"); /* check for end of page */
    page_no++;
    p2_headings();
    lines = 7;
    }

    fprintf(report_ptr,"%-2c%-7s",
    ptr->cre.rec_type,
    ptr->cre.cust_code);

    switch(ptr->cre.rec_type)
    {
    case 'c':
    case 'C':strcpy(temp_name, ptr->cre.cust_name);
    strcat(temp_name, SPACES);
    strcpy(temp_addr, ptr->cre.cust_addr);
    strcat(temp_addr, SPACES);
    fprintf(report_ptr,"%-36s%-62s %09f %07ld\n",
    temp_name,
    temp_addr,
    ptr->cre.cust_bal,
    ptr->cre.credit_limit);
    lines++;
    return;
    case 'd':
    case 'D':lines++;
    return;
    case 'i':
    case 'I':
    case 'r':
    case 'R':fprintf(report_ptr,"%-8s%-6s\n",
    ptr->iss.part_no,
    ptr->iss.quantity);
    lines++;
    return;
    default: return;
    }

    } /* end printout() */



    void summary2(int c, int d, int i, int r, int t_rec, int c_tot)
    {


    fprintf(report_ptr,"\n\n\n%-38s%-6d\n%-38s%-6d\n",
    "NEW CUSTOMERS:",c,
    "DELETED CUSTOMERS:",d);
    fprintf(report_ptr,"%-38s%-6d\n%-38s%-6d\n\n",
    "ISSUE FROM STOCK:",i,
    "RECIEPTS:",r);
    fprintf(report_ptr,"\n%-38s%-6d\n%-38s%-6d",
    "TOTAL CUSTOMERS:",c_tot,
    "TOTAL TRANSACTIONS:",t_rec);
    fprintf(report_ptr,"\n\n\n%-55s",
    "*** END OF TRANSACTION REPORT ***");
    } /* end summary2() */


    int compare(const void*a, const void*b)
    {
    int val;

    val = strcmp( ((union s_rec*)a)->cre.cust_code,
    ((union s_rec*)b)->cre.cust_code);
    if(val)
    {
    return val;
    }
    return ( ((union s_rec*)b)->cre.rec_type -
    ((union s_rec*)a)->cre.rec_type );
    }

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    I don't even want to read through that. Usually when I got those errors it was because of an improper return 0 somewhere. I'll leave this to someone who wants to read through the code.

    I did notice this:
    > void main()
    That's wrong.

    : : Edit : :
    Turbo isn't the best of compilers in my opinion. Remember to use code tags. This way it's alot easier for others to look for errors.
    Last edited by Shadow; 04-28-2002 at 10:57 AM.
    The world is waiting. I must leave you now.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Couple of pretty serious mis-uses of printf/scanf

    zzz.c:67: warning: return type of `main' is not `int'
    void main()
    Should be int main

    zzz.c: In function `p2_headings':
    zzz.c:187: warning: too few arguments for format
    fprintf(report_ptr,"\n%s%-6s%-7s%-6s%-94s%-10s\n",
    "REC","CUST",
    "PART","I/R" // Missing comma here?
    "CUSTOMER",
    "CREDIT");

    zzz.c: In function `printout':
    zzz.c:237: warning: format argument is not a pointer (arg 4)
    case 'R':fprintf(report_ptr,"%-8s%-6s\n", // %d for ints
    ptr->iss.part_no,
    ptr->iss.quantity);

  6. #6
    Registered User breed's Avatar
    Join Date
    Oct 2001
    Posts
    91
    Hi Stormswift,

    I know where your going with this, I have just submitted my two progs to computeach.
    Try getting rid of the ampersand before buf, let me know if it works out.

    while( (fread(&buf, SIZE, 1, in_ptr) ) == 1 )


    also if you feel you need to talk to someone who has either been through or going through the same mind blowing experiences,

    then try this site......the void main gang are all here
    Before you judge a man, walk a mile in his
    shoes. After that, who cares.. He's a mile away and you've got
    his shoes.
    ************William Connoly

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM