473,404 Members | 2,187 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,404 software developers and data experts.

General Protection Exception error

Hi,

I am a student of mathematics and quite new to programming in C. I am trying to write a code to construct an array which at every step has to compare the value of the current element with all the existing elements in the array.

The code is compiling without error. However whenever I try to run it, I get General Protection Exception.

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4.  
  5. float admval(float *m, float p, int q);
  6.  
  7. void main(){
  8. int dim=0, i=0, j=0, k=0, l1=0, temp1=0, ndone=0, mav =0;
  9. int i1=0, kj=0, ij=0, jj=0, sd=0;
  10. int seq[30];
  11. float rel[30][30];
  12. float tol[30], done[30], at[30], mava[30];
  13. float minmav=0;
  14. //float admval(float *m, float p, int q);
  15. printf("Enter the dimension of matrix \n");
  16. scanf("%d", &dim);
  17. for (i=0;i<dim;i++)
  18. {
  19. for(j=0;j<dim;j++)
  20. {
  21. printf("Enter the %d%d th element of the matrix \n", i,j);
  22. scanf("%f", &rel[i][j]);
  23. }
  24. }
  25.  
  26. for (i=0;i<dim;i++)
  27. {
  28. for(j=0;j<dim;j++)
  29. {
  30. printf("The %d%d th element of the matrix is %f \n", i, j, rel[i][j]);
  31. }
  32. }
  33.  printf("Enter the sequence of elements of the matrix \n");
  34.  for(k=0; k<dim; k++)
  35.  {
  36.   scanf ("%d", &seq[k]);
  37.  }
  38.  printf("the sequence is \n");
  39.  for(k=0; k<dim; k++)
  40.  {
  41.   printf ("%d \n", seq[k]);
  42.  }
  43.  l1=seq[0]-1;
  44.  tol[l1] = rel[l1][l1];
  45.  done[0] = 1;
  46.  ndone =1;
  47.  printf("av is %f", tol[l1]);
  48.  
  49.  for (i1=0; i1<dim; i++)
  50.  {
  51.   if (ndone==dim)
  52.     {
  53.      goto l1;
  54.     }
  55.   for (kj =0; kj<dim; kj++)
  56.   {
  57.     ij=seq[kj];
  58.     if (done[ij] ==0)
  59.     {
  60.         goto l2;
  61.     }
  62.   }
  63.   }
  64.  
  65.  l1:
  66.     printf("results :");
  67.     for (i=0; i<dim; i++)
  68.     {
  69.         printf("\n %f", at[i]);
  70.     }
  71.  
  72.  l2:
  73.     sd=1;
  74.     goto l4;
  75.     for (jj=0; jj<dim;j++)
  76.     {
  77.         if ((jj == ij) ||( done[jj] == 0))
  78.         {
  79.             goto l3;
  80.         }
  81.         else if(at[jj]>rel[jj][ij])
  82.         {
  83.           mav = rel[jj][ij];
  84.          }
  85.         else
  86.         {
  87.             mav=rel[ij][jj];
  88.         }
  89.         sd= sd+1;
  90.         mava[sd]=mav;
  91.         printf("mav = %f", mav);
  92.      l3:
  93.     }
  94.     minmav =5000;
  95.     admval(mava, minmav, ndone);
  96.   l4:
  97.   printf ("now computing .....");
  98.     temp1=rel[ij][ij];
  99.     mava[sd]= temp1;
  100. //   l2=0, d=0,
  101.  //for(k=1;k<dim;k++)
  102.  //{
  103.  //l2=seq[k]-1;
  104. // admval(l1,l2);
  105. //temp1= tol[l1];
  106. //temp2= rel[l1][l2];
  107. // if (tol[l1] <= rel[l1][l2])
  108.       //    av[l2]= rel[l2][l2];
  109.  
  110. // else
  111.      //{
  112.       //    av[l2]= rel[l1][l2];
  113.  //    }
  114.  
  115. //done[d]=l2;
  116. //d++;
  117.  
  118.  
  119.  // }
  120. }
  121.  
  122. float admval (float m[], float p, int q)
  123. {
  124.   int kk;
  125.   for (kk=0; kk< q+1; kk++)
  126.   {
  127.     if (m[kk]< p)
  128.     {
  129.         p=m[kk];
  130.     }
  131.   }
  132.   return(p);
  133.   }
  134.  
Hope somebody can help me.

Thanks in advance
Apr 14 '09 #1
2 3026
newb16
687 512MB
Works fine for me using cygwin.
Apr 14 '09 #2
donbock
2,426 Expert 2GB
@subhasree
You should validate the dim input to make sure it is legal (1 <= dim <= 30). There are other operator inputs (for instance seq) that should be validated too; although their legal ranges may differ from that of dim.


@subhasree
Curiously, "%f" converts a float in scanf, but a double in printf. Try adding an explicit cast to double in the printf line. You have several other printf lines with the same potential problem.


@subhasree
You probably meant to increment i1 rather than i.


@subhasree
Variables and labels are in different namespaces so it is legal and unambiguous to use the same name for both. However, people tend to get confused so the practice is frowned on.


@subhasree
You will never get to the for loop.


@subhasree
You probably meant to increment jj rather than j.

@subhasree
I haven't analyzed the code so I don't know, but how big do you expect sd to get? Is it bound by dim or by dim^2? If the latter then you need to increase the array size in the array definition accordingly.
Apr 14 '09 #3

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

Similar topics

2
by: SteveS | last post by:
Hello all. This problem is stumping me.... I run a page called "default.aspx". For some reason when I execute this page, I get the error below. It seems to run through the entire code behind...
0
by: Paiman Allage | last post by:
Hello all, I hope you can help me. I have developed an ".NET" application and started to deploy the application. However, I am haveing a problem, where when I compile the program on my laptop,...
3
by: Steve | last post by:
I have some general catch clauses in my app as follows: try { } catch(Exception ex) { } try
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
37
by: dmoran21 | last post by:
I am a mathematician trying to write a program in C to do some curve fitting. When I get to the point where I attempt to enter data in my arrays, I get a General Protection Exception error message....
2
by: akmkat | last post by:
When I try to compile the following code with N = 1024, "General Protection Exception" occurs, but wehn N < 20, there is no problem. I need N = 1024, what'll I do? Plz help anyone #include...
0
by: KhoaNguyen | last post by:
Hi, When i compiled these two source files, it gives me an error saying: Inaccesssible Due to its protection level. ------------Base Class----------------- using System; using...
0
by: johnkamal | last post by:
Hi, Some times while opening a page, I am getting the following error message, Please help me to rectify the problem. Server Error in '/' Application. General network error. Check your...
1
by: manhquynh8x | last post by:
I am programming a data compession program. It is used to compress a text file. After run program, i see this message: Exception 13: General protection fault at o1A7.. The compiler is Turbo C++...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.