473,386 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Runtime Memory Error

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 2278
Banfa
9,065 Expert Mod 8TB
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 512MB
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
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...
5
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...
7
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...
1
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...
8
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;...
2
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)...
1
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)...
3
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...
4
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...
3
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" ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.