The error during run time is:"Your code has stopped its execution with a non-zero (failure) exit value.This is generally due to run time Exceptions like Memory Access Violation and Floating Point Exception. Please check your code for run time Exceptions and try again.". What could be the error? Please help. -
#include<conio.h>
-
#include<stdio.h>
-
struct amicable
-
{
-
int **amicablePairs;
-
int size;
-
};
-
struct amicable* getAmicablePairs(int startnum,int endnum);
-
int main()
-
{
-
struct amicable *ami;
-
int i,startnum,endnum;
-
clrscr();
-
-
ami=getAmicablePairs(100,2000);
-
printf("{");
-
for(i=0;i<ami->size;i++)
-
{
-
printf("{%d %d}",ami->amicablePairs[i][0],ami->amicablePairs[i][1]);
-
}
-
printf("}");
-
getch();
-
return 0;
-
}
-
-
-
struct amicable * getAmicablePairs(int startnum,int endnum)
-
{
-
struct amicable *amic;
-
int i,j,divisor=0,divisor1=0,k=0,l,**p;
-
p=malloc(15*sizeof(int*));
-
if(p==NULL)
-
printf("failed for p");
-
if(startnum>0&&endnum>0&&startnum<endnum&&endnum<=15000)
-
{
-
for(i=startnum;i<=endnum;i++)
-
{
-
for(j=1;j<=i/2;j++)
-
{
-
if(i%j==0)
-
divisor+=j;
-
}
-
if(divisor<=endnum&&divisor>i)
-
{
-
for(l=1;l<=divisor/2;l++)
-
{
-
if(divisor%l==0)
-
divisor1+=l;
-
}
-
if(divisor1==i)
-
{
-
p[k]=malloc(2*sizeof(int));
-
if(p[k]==NULL)
-
printf("failed for loop");
-
p[k][0]=i;p[k][1]=divisor;
-
//amic->amicablePairs[k][0]=i;
-
//amic->amicablePairs[k][1]=divisor;
-
k++;
-
}
-
}
-
divisor=0;divisor1=0;
-
}
-
if(k==1)
-
goto here;
-
amic->size=k;
-
amic->amicablePairs=p;
-
return amic;
-
}
-
else
-
here:return NULL;
-
}
-
2 2298 Banfa 9,065
Recognized Expert Moderator Expert
You have a limit to your malloc memory of 15 but you never ensure that k does not exceed this limit.
Amic is not initialized in the function and points nowhere, but then you write to its members.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Rao Kachibhotla |
last post by:
Hi,
I have a Deskband project that builds a DLL. When I
register the DLL, I get the usual success dialog, but i
also get "Visual C++ RunTime error" that says "This
application has requested the Runtime to terminate in an
unusual way. Please request product support for this
application."
I noticed that DLL has unloaded at this point. Also, my
|
by: VinnieT |
last post by:
I have a load balanced system that consists of 3 production servers. There
are about 20 different applications that are used on these boxes. One of my
applications in particular is used more than the others. Since updating 2
applications, I have had problems on the event log of the servers, following
stopping of the aspnet_ws.exe process.
Something is causing the following error in the windows application event log:
The description for...
|
by: cppaddict |
last post by:
Hi,
I've been trying to debug a strange runtime error for the last 5
hours... I'm hoping someone might have an insight about it.
I have an application that creates a vector of MyDisplay objects
(MyDisplay is a custom class) and then uses them in various ways. The
application has been compiling and running fine. Then I added a
member variable of type enum to MyDisplay. So my class def now looks
like this:
|
by: Lumpierbritches |
last post by:
Thank you in advance for any and all assistance. I'm trying to make it where at
runtime my program will allow the introduction of an image.
I've tried bound, unbound and images. On the bound OLE Object, sometimes I get
the Insert menu, and other times I don't. I want to be able to at runtime link
a file image to a particular record. Is there an easy way to do this, and if
so, is there code to assist me in this task?
Michael
|
by: Nanda |
last post by:
hi,
I am trying to generate parameters for the updatecommand
at runtime.
this.oleDbDeleteCommand1.CommandText=cmdtext;
this.oleDbDeleteCommand1.Connection =this.oleDbConnection1;
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_ApplicantName",
dataset.Tables.Columns.DataType, 50,
| |
by: SenthilVel |
last post by:
Hi All
i am getting an error in remoting proxies like the below :
Exception rethrown at :
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
|
by: SenthilVel |
last post by:
Hi All
i am getting an error in remoting proxies like the below :
Exception rethrown at :
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
|
by: schizoid_man |
last post by:
Hi,
I have the following code snippets and I get a std::bad_alloc error
where I think there should be none. I've attached the relevant bits of
the base class, derived class and the .cpp file containing the main()
method.
I'd really appreciate any help in getting this error sorted out.
Thanks,
|
by: r.z. |
last post by:
My program behaves very strange. I keep getting the following error:
'The instruction at "some address" referenced memory at "some address". The
memory could not be written"'
The program consists of:
int main( int argc, char* argv )
{
//here is some third party function that configures graphic environment
{
app my_app; //this is local so that I'm sure it's destroyed before
next step
|
by: Baby Lion |
last post by:
hi,everyone ,
one Runtime error occur when running , maybe it's about assigning
memory .
I need your help , thanks.
It's about the travelling sellman problem .
//#include "stdafx.h"
//TSPÎÊÌâµÄ½â·¨
#include<stdlib.h>
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |