delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/07/16:01:53

From: brunobg AT geocities DOT com (Bruno Barberi Gnecco)
Newsgroups: comp.os.msdos.djgpp
Subject: Struct gives a GPF
Date: Sat, 07 Mar 1998 20:54:46 GMT
Organization: UNINET (Unisys Brasil Internet Access Service)
Lines: 105
Message-ID: <3501b1f3.61286@news.unisys.com.br>
NNTP-Posting-Host: saonb03p31.unisys.com.br
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hello!
	I've got a problem when running a program. It worked well, but then I
added a second struct, and it shows this error:

Exiting due to signal SIGSEGV
General Protection Fault at eip=0000177d
eax=435c5357 ebx=0004f180 ecx=0004d6fc edx=00000002 esi=00001568 edi=0004d894
ebp=0004d894 esp=0004d6e4 program=E:\DJGPP\POLI\EP1.EXE
cs: sel=00a7  base=82e99000  limit=0005ffff
ds: sel=00af  base=82e99000  limit=0005ffff
es: sel=00af  base=82e99000  limit=0005ffff
fs: sel=0087  base=00022100  limit=0000ffff
gs: sel=00bf  base=00000000  limit=ffffffff
ss: sel=00af  base=82e99000  limit=0005ffff

Call frame traceback EIPs:
  0x0000177d
  0x00001eee

	Sometimes it shows another error, relating to __crt1_startup+138. What is
the problem? below is the source (note that it's incomplete, and some parts may be
missing due to the debugging). I also tried to set the _crt0_startup_flags the FAQ
says, but the same error showed up. What's wrong? If the second struct is not
used, all goes fine, but I need it... Thanks a lot,

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#define   min(b,c)    (((b) <= (c)) ? (b) : (c))
#define   max(b,c)    (((b) >= (c)) ? (b) : (c))

int main() {
    struct motorista {
       int pontos, dia, mes, ano, carteira;
    };
    struct multa {
       int infr, dia, mes, ano;
    };
    int tabela[] = {0, 4, 5, 5, 7, 7};
    struct motorista mot[3];
    int count;
    struct multa database[20];
    int *point, *infr, *temp;

    mot[0].pontos = 0;
    mot[1].pontos = 0;
    mot[2].pontos = 0;
    mot[0].carteira = 0;
    mot[1].carteira = 0;
    mot[2].carteira = 0;

    for ( count = 0; count < 20; count++ ) {
       printf("Type the numbers: ");
       scanf("%d %d %d %d", &database[count].infr, &database[count].dia,
&database[count].mes, &database[count].ano);

       if ( database[count].infr == 0 && database[count].dia == 0 &&
database[count].mes == 0 && database[count].ano == 0 ) {
          break;
       }
       *temp = database[count].infr;
       *infr = tabela[*temp];
       printf("chegou aqui");
       *point = min(mot[1].pontos , mot[2].pontos );
       if ( (mot[0].pontos + *infr)>19 && (mot[1].pontos + *infr)>19 &&
(mot[2].pontos + *infr)>19) {
          *point = max(mot[1].pontos, mot[2].pontos);
          if (mot[0].pontos >= *point && mot[0].pontos  <= 19 ) {
              mot[0].pontos += *infr;
          }
          else if ( mot[1].pontos >= mot[2].pontos && mot[1].pontos <= 19) {
              mot[1].pontos += *infr;
          }
          else if (mot[2].pontos <= 19) {
              mot[2].pontos += *infr;
          }
          else printf("Error");
       }
       else if ( mot[0].pontos <= *point && mot[0].pontos <= 19 ) {
          mot[0].pontos += *infr;
       }
       else if ( mot[1].pontos <=mot[2].pontos && mot[0].pontos <=19 ) {
          mot[1].pontos += *infr;
       }
       else if (mot[2].pontos <= 19) mot[2].pontos += *infr;
       else printf("Erro indefinido!");
    }

    printf("I DD MM ANO\t\tNo. de Pontos\n");
    for (count = 0; count < 20; count++) {
       if(database[count].infr == 0 ) {
          break;
       }
       printf("%d %d %d %d\t\t   %d\n", database[count].infr, database[count].dia,
database[count].mes, database[count].ano, tabela[database[count].infr]);
    }
}


"There's never enough time to do all the nothing you want" Bill Watterson 
"Is ALL that we see or seem / But a dream within a dream?" - Edgar A. Poe
Bruno Barberi Gnecco <brunobg AT geocities DOT com> ICQ #1383173 - PGP 5.0i user
-=My other OS is Linux=- 3DS4, Max, Rhino, Photoshop and everything about 
computer graphics? It sure is on Graphx Page!!! http://graphx.home.ml.org

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019