Click here to Skip to main content
15,886,798 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I declared as int a[1000000][1000000]; Then I am getting error as array size is too large.
Then I chaged as long a[1000000][1000000], though getting same error.
How can I solve this problem?
my program is
#include<stdio.h>  
#define size 100000           
  int main()
  {
  
 //int* a;
//a=(int *)malloc(1000);
  
  long a[size][size],c,d,n,i,j,q1=0,q2=0,q3=0,q4=0,will=1,b[20][20],k=0;
  char p;
  //printf("enter the number of co ordinate");
  scanf("%d",&n);
  for(i=0;i<n;i++)>
  for(j=0;j<2;j++)
  scanf("%d",&a[i][j]);
  void quadrant(int temp1,int temp2)
  {
                   
         if(temp1>=0&&temp2>=0)
        q1++;
      else if(temp1>=0&&temp2<=0)
        q2++;
      else if(temp1<0&&temp2<0)
        q3++;
      else if(temp1<=0&&temp2>=0)
         q4++;
 
   }
//printf("enter no of operations");
scanf("%d",&will);
                
while(will>0)
{
p=getchar();
scanf("%c",&p);
switch(p)
{
case 'x': 
                scanf("%d %d",&c,&d);
                  for(i=c-1;i<d;i++)>
                  a[i][1]=-(a[i][1]);break;
case 'y': 
                scanf("%d %d",&c,&d);
                for(i=c-1;i<d;i++)>
                a[i][0]=-(a[i][0]);break;
case 'c':       scanf("%d %d",&c,&d);
                for(i=0;i<=n-1;i++)
                {
                 int temp1,temp2;
                 temp1=a[i][0];
                 temp2=a[i][1];
              
                 quadrant(temp1,temp2);
                } 
               b[k][0]=q1;
               b[k][1]=q2 ;
               b[k][2]=q3;
               b[k][3]=q4; 
             
                  k=k+1; 
    q1=0;
    q2=0;
    q3=0;
    q4=0; 
                 
                  break;
case 'p':   printf(" the co-ordinates are:\n");
               for(i=0;i<n;i++)>
               {
                 for(j=0;j<2;j++)
                {
              printf("%d   ",a[i][j]);
                 }
                printf("\n");
                 } 
                 break;                               
     
default: printf("enter the correct choice\n");break;
}
if(will==1)
for(i=0;i<k;i++)>
{
printf("%d %d %d %d\n",b[i][0],b[i][1],b[i][2],b[i][3]);
}
will--;
}
}
</stdio.h>
Posted
Updated 5-Sep-11 21:48pm
v6
Comments
Chuck O'Toole 6-Sep-11 3:52am    
OK, so you posted a newer version of the program but you still are using 100,000 x 100,000 for the data when your program only needs 100,000 x 2 ! Are you just going to keep chaning things until it works or are you interested in understanding why it doesn't?

Store data in the file organized for random access. Keep the file opened, define two function to store and retrieve integer by index.

—SA
 
Share this answer
 
Comments
Espen Harlinn 6-Sep-11 19:14pm    
5'ed, that would work as long as the OS is capable of managing the filesize.
Sergey Alexandrovich Kryukov 7-Sep-11 1:22am    
Thank you, Espen.
--SA
1) See my answer to your other question about the segmentation fault.
2) you seriously need to go back and learn more about double dimensioned arrays.

1,000,000 x 1,000,000 is 1,000,000,000,000 (1 Trillion) entries. "int" is 4 bytes apiece = 4 TB of memory (not many systems will let you have a program that big :)). When you changed it to "long", you now need 8 bytes for each items, doubling your memory requirement.

1) you aren't using the 2nd dimension in your program beyond [x,0] and [x,1] so why you think you need the other 999,998 entries is beyone me.

2) while it is possible to store 1,000,000 "ints" (only 4MB of memory needed), you might want to consider disk files and other ways of storing large amounts of data and processing it in "views" rather than in one big memory chunk.

3) Since this is obviously homework, ask your instructor what the realistic sizes of the data should be and, if he/she suggested 1 Million entries, find out why they think that's reasonable and who's going to type in all that data :)
 
Share this answer
 
Comments
CHINA PING 6-Sep-11 3:46am    
agree!(not many systems will let you have a program that big)is correct。you need to store 1000000,if you want to store them via 2D array,1000 x 1000 is enough。good luck
Sergey Alexandrovich Kryukov 7-Sep-11 1:23am    
Good points, my 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900