473,795 Members | 2,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Runtime Memory Error

4 New Member
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.
Expand|Select|Wrap|Line Numbers
  1. #include<conio.h>
  2. #include<stdio.h>
  3. struct amicable
  4. {
  5. int **amicablePairs;
  6. int size;
  7. };
  8. struct amicable* getAmicablePairs(int startnum,int endnum);
  9. int main()
  10. {
  11. struct amicable *ami;
  12. int i,startnum,endnum;
  13. clrscr();
  14.  
  15. ami=getAmicablePairs(100,2000);
  16. printf("{");
  17. for(i=0;i<ami->size;i++)
  18. {
  19. printf("{%d %d}",ami->amicablePairs[i][0],ami->amicablePairs[i][1]);
  20. }
  21. printf("}");
  22. getch();
  23. return 0;
  24. }
  25.  
  26.  
  27. struct amicable * getAmicablePairs(int startnum,int endnum)
  28. {
  29. struct amicable *amic;
  30. int i,j,divisor=0,divisor1=0,k=0,l,**p;
  31. p=malloc(15*sizeof(int*));
  32. if(p==NULL)
  33. printf("failed for p");
  34. if(startnum>0&&endnum>0&&startnum<endnum&&endnum<=15000)
  35. {
  36. for(i=startnum;i<=endnum;i++)
  37. {
  38. for(j=1;j<=i/2;j++)
  39. {
  40. if(i%j==0)
  41. divisor+=j;
  42. }
  43. if(divisor<=endnum&&divisor>i)
  44. {
  45. for(l=1;l<=divisor/2;l++)
  46. {
  47. if(divisor%l==0)
  48. divisor1+=l;
  49. }
  50. if(divisor1==i)
  51. {
  52. p[k]=malloc(2*sizeof(int));
  53. if(p[k]==NULL)
  54. printf("failed for loop");
  55. p[k][0]=i;p[k][1]=divisor;
  56. //amic->amicablePairs[k][0]=i;
  57. //amic->amicablePairs[k][1]=divisor;
  58. k++;
  59. }
  60. }
  61. divisor=0;divisor1=0;
  62. }
  63. if(k==1)
  64. goto here;
  65. amic->size=k;
  66. amic->amicablePairs=p;
  67. return amic;
  68. }
  69. else
  70. here:return NULL;
  71. }
  72.  
Nov 23 '09 #1
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.
Nov 23 '09 #2
newb16
687 Contributor
Amic is not initialized in the function and points nowhere, but then you write to its members.
Nov 23 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
7807
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
5
4662
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...
7
1953
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:
1
1862
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
8
5971
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,
2
3725
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&
1
2483
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&
3
18112
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,
4
1447
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
3
2759
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>
0
9672
marktang
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...
0
10438
Oralloy
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...
0
9042
agi2029
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...
1
7540
isladogs
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...
0
5437
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...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.