cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/02/20:54:12

Date: Sun, 2 Feb 1997 20:44:07 -0500 (EST)
From: Michael Phelps <morphine AT hops DOT cs DOT jhu DOT edu>
To: Pyro Technic <invid AT dmv DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: SIGSEV hates me
In-Reply-To: <32F56281.2014@dmv.com>
Message-ID: <Pine.GSO.3.95.970202203900.20758B-100000@hops.cs.jhu.edu>
MIME-Version: 1.0

On Sun, 2 Feb 1997, Pyro Technic wrote:

> My prog is a stupid little prog for a math problem. It's due in 14
> hours. I need help bad.The prog, B low, compiles w/ just 1 warning
> 
> D:\PROGS>gxx -o TOG.exe TOG#2.cpp
> TOG#2.cpp: In function `int main(...)':
> TOG#2.cpp:30: warning: implicit declaration of function `int getch(...)'
> 
> when run though it immediately exits and just leaves this
> Exiting due to signal SIGSEGV
> Stack Fault at eip=00001603
> eax=00003dbc ebx=00003dbc ecx=00000000 edx=00000000 esi=00000054
> edi=00020954
> ebp=00060928 esp=000608dc program=
> cs: sel=00a7  base=83dff000  limit=0006ffff
> ds: sel=00af  base=83dff000  limit=0006ffff
> es: sel=00af  base=83dff000  limit=0006ffff
> fs: sel=0087  base=0000bf10  limit=0000ffff
> gs: sel=00bf  base=00000000  limit=ffffffff
> ss: sel=00af  base=83dff000  limit=0006ffff
> 
> Call frame traceback EIPs:
>   0x00001603
> 
> 
> 	This is the program.
> 
> <here>
> // Test of geinus problem #2 for 9th grade math
> 
> #include <iostream.h>

Also #include <stdio.h> /* because you use getch() below */

> 
> void main()

C++ (especially) wants you to declare int main()

> 	{
> 	char dummy;
> 	int num2, temp, digit[3], j, i;

			^^^^^^^^
That should be int digit[4];  Remember, in C, when you declare an array
size, you give it the number of elements (which starts at zero), and _NOT_
the highest element accessible.  (Your program actually references
digit[3], while you only declare digit[0], digit[1], and digit[2], thus
causing the violation.)

 > float num1; > > 	for(i=1; i < 10000; ++i)
> 		{
> 		num1 = i;
> 		num2 = i * 4;
> 		for(j=3; j>=0; ++j)
> 			{
> 			temp = (int)num1 % 10;
> 			digit[j]=temp;
> 			num1 /= 10;
> 			num1 -= (temp/10); 
> 			}
> 		num1 = 0;
> 		num1 = digit[0];
> 		num1 += digit[1] * 10;
> 		num1 += digit[2] * 100;
> 		num1 += digit[3] * 1000;
> 		if(num1==num2)
> 			{
> 			cout << '\n' << num1 << " * 4 = " << num2 << "\nPush a key to
> continue" << flush; 
> 			dummy = getch();

Also, getch() isn't in iostream.h, but rather stdio.h.  (Usually C++
programs don't use stdio that much.)

> 			}
> 		else
> 			cout << ".";
> 		}	
> 	}
> <to here>
> 
> please answer, I'm a desperate newbie. Thanks in advance.
> 
> 	Pyro
> 


						---Michael Phelps
						   morphine AT cs DOT jhu DOT edu


                               CH3
                               |
                               N
                             / |
                     ______/   |
                    /      \   CH2
             _____/         \__|__      
           //     \\        /  |  \\     
         //        \\______/___CH2 \\  
          \        /       \       /
           \______/         \_____/
          / ------ \       /      \
        OH           \   /         OH
                       O
 
                   Morphine



- Raw text -


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