| | |
Help - Problem with array
Thread Solved |
•
•
Join Date: Jan 2007
Posts: 7
Reputation:
Solved Threads: 0
I am writing a C program using Dev-CPP. It uses a 3 dimensional array to store around 350 values as shown below.
I get a valid output when I read the array with the following code
but it stops abruptly with a error msg when i run a code like this...
The program stops exactly when the last line is executed...
. It get compiled without any error
help me to read the array using the int values...
c Syntax (Toggle Plain Text)
db[2][0][1]=3278; db[2][0][4]=2368; db[3][0][3]=6686; db[2][0][6]=7224; .. .. ..
I get a valid output when I read the array with the following code
c Syntax (Toggle Plain Text)
zone = db[2][0][1]; printf("%d",zone);
but it stops abruptly with a error msg when i run a code like this...
c Syntax (Toggle Plain Text)
int h,t,o; h=2; t=0; o=1; zone = db[h][t][o];
The program stops exactly when the last line is executed...
. It get compiled without any error help me to read the array using the int values...
•
•
Join Date: Jan 2007
Posts: 7
Reputation:
Solved Threads: 0
I am sorry. I should have done that first..
the maximum value is 7789 and the minimum value is 3278.
c Syntax (Toggle Plain Text)
int db[9][9][9];
the maximum value is 7789 and the minimum value is 3278.
The values you put in the array are not relevent to your problem. I suspect the actual error is elsewhere in your program because what you posted looks ok. Without more code its impossible to say what your problem is.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Either that, or you have some miniscule amount of RAM in your computer. What's your compiler? It's highly unlikely, but a crappy old compiler has much different limits than a modern one.
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
Hello there.
Yes, an old compiler imposes a limit on the amount of memory that can be allocated to a single variable, but if that were the senario, the program execution would have halted at the point he has declared the three dimensional array.
I hope you realize that even though he hasn't stored any values initially in his array, the space has been nonetheless allocated to him. I don't think any failed attempt after the allocation is due to the old compiler.
And as far as RAM is concerned, he is allocating 729 * 4 bytes ~ 2.85 KB. I don't think this should be as such a problem...
Thank you.
•
•
•
•
Either that, or you have some miniscule amount of RAM in your computer. What's your compiler? It's highly unlikely, but a crappy old compiler has much different limits than a modern one.
I hope you realize that even though he hasn't stored any values initially in his array, the space has been nonetheless allocated to him. I don't think any failed attempt after the allocation is due to the old compiler.
And as far as RAM is concerned, he is allocating 729 * 4 bytes ~ 2.85 KB. I don't think this should be as such a problem...

Thank you.
Last edited by ~s.o.s~; Jan 1st, 2007 at 10:30 pm.
I don't accept change; I don't deserve to live.
•
•
•
•
Hello there.
Yes, an old compiler imposes a limit on the amount of memory that can be allocated to a single variable, but if that were the senario, the program execution would have halted at the point he has declared the three dimensional array.
I hope you realize that even though he hasn't stored any values initially in his array, the space has been nonetheless allocated to him. I don't think any failed attempt after the allocation is due to the old compiler.
And as far as RAM is concerned, he is allocating 729 * 4 bytes ~ 2.85 KB. I don't think this should be as such a problem...
Ancient Dragon is right - there's an error somewhere else in your program. Post your entire code so that we can criticize... I mean, correct, your code. :cheesy:
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
Hello there.
Ah..just to clear the matters up...even if we dynamically allocated 2.9KB of memory, it wouldn't be such a problem, unless of course, you were doing realloc i.e. allocating memory during runtime and exceeding the limitations imposed by the current memory model of the compiler.
Thank you.
•
•
•
•
You're right - I guess I was thinking in terms of dynamic memory allocation...
Thank you.
I don't accept change; I don't deserve to live.
•
•
Join Date: Jan 2007
Posts: 7
Reputation:
Solved Threads: 0
here is the code.. so that you could correct....
this is a program to find time zone from area code...
I am using dev-c++ ver 4.9.9.2 to develop this program.
this is a program to find time zone from area code...
c Syntax (Toggle Plain Text)
#include <stdio.h> #include <stdlib.h> void db_init(void);/*function to initialise db[9][9][9] to zero*/ void db_init1(void);/*function to initialise db[9][9][9] to with the database*/ int db[9][9][9]; /*array to store the value*/ int n; int zone; int main() { db_init();/*function to initialise db[9][9][9] to zero*/ db_init1();/*function to initialise db[9][9][9] to with the database*/ int hundred,ten,one; int query[100];/*array to get input from user*/ int filtered[100];/*array to store the only the number in the input from user*/ int i=0,j,k; for(i=0;i<=100;i++)/*function to initialise filtered to zero*/ filtered[i]=0; i=0; printf("Hi! Thank you for using Siva's time zone locator.\nPress any key to continue...."); getch(); zone = db[2][0][1];/*not part of program. only to check*/ printf("%d",zone);/*not part of program. only to check*/ getch(); system("CLS"); printf("Please enter upto 20 three digit area codes and type \\ and hit enter\n"); /* \ is to indicate end of input*/ while(i!=100 && (query[i]=getchar())!=92)/*to get input from user*/ { ++i; } n=i-1;/* -1 to exclude the \ at the end of the array*/ k=0; for(i=0;i<=n;i++) { j=query[i]; if (j>47 && j<58)/* to move the element in query[] to filtered[] if its a number*/ { filtered[k]=j; ++k; } else ; } for (i=0;i<=k;i) { hundred=filtered[i]; ten=filtered[i+1]; one=filtered[i+2]; putchar(hundred); putchar(ten); putchar(one);/*works great till here*/ zone = db[hundred][ten][one];/*problem starts here*/ switch (zone) { case 3278: printf("\tEastern Standard Time Zones"); case 2368: printf("\tCentral Standard Time Zones"); case 6686: printf("\tMountain Standard Time Zones"); case 7224: printf("\tPacific Standard Time Zones"); case 2389: printf("\tEastern & Central Time Zones"); case 2689: printf("\tCentral & Mountain Time Zones"); case 6289: printf("\tMountain & Central Time Zones"); case 6789: printf("\tMountain & Pacific Time Zones"); case 2289: printf("\tAleutian & Alaskan Time Zones"); case 2852: printf("\tAtlantic Time Zones"); case 6389: printf("\tNewfoundland Time Zone (Canadian)"); case 7289: printf("\tPacific & Alaskan Time Zones"); case 7789: printf("\tSamoan Standard Time Zones"); default: printf("invalid code"); } i=i+3; } return 0; } void db_init(void) { /*function to initialise db[9][9][9] to zero*/ /*using a seperate function because programs stops after this if used in main()*/ int i,j,k; for (i=0;i<=9;i++) { for (j=0;j<=9;j++) { for (k=0;k<=9;k++) { db[i][j][k]=0; } } } } void db_init1(void) { /*function to initialise db[9][9][9] to with the database*/ /*using a seperate function because programs stops after this if used in main()*/ db[2][0][1]=3278;/*Eastern Time Zone*/ db[2][0][2]=3278; db[2][0][3]=3278; db[2][0][7]=3278; db[2][1][2]=3278; db[2][1][5]=3278; db[2][1][6]=3278; db[2][2][6]=3278; db[2][2][9]=3278; db[2][3][1]=3278; db[2][3][4]=3278; db[2][3][9]=3278; db[2][4][0]=3278; db[2][4][8]=3278; db[2][5][2]=3278; db[2][6][7]=3278; db[2][6][9]=3278; db[2][7][6]=3278; db[2][8][9]=3278; db[3][0][1]=3278; db[3][0][2]=3278; db[3][0][4]=3278; db[3][0][5]=3278; db[3][1][3]=3278; db[3][1][5]=3278; db[3][2][1]=3278; db[3][3][0]=3278; db[3][3][6]=3278; db[3][3][9]=3278; db[3][4][5]=3278; db[3][4][7]=3278; db[3][5][1]=3278; db[3][5][2]=3278; db[3][8][6]=3278; db[4][0][1]=3278; db[4][0][4]=3278; db[4][0][7]=3278; db[4][1][0]=3278; db[4][1][2]=3278; db[4][1][3]=3278; db[4][1][6]=3278; db[4][1][8]=3278; db[4][1][9]=3278; db[4][3][4]=3278; db[4][3][8]=3278; db[4][4][0]=3278; db[4][4][3]=3278; db[4][5][0]=3278; db[4][7][0]=3278; db[4][7][5]=3278; db[4][7][8]=3278; db[4][8][4]=3278; db[5][0][2]=3278; db[5][0][8]=3278; db[5][1][3]=3278; db[5][1][4]=3278; db[5][1][6]=3278; db[5][1][7]=3278; db[5][1][8]=3278; db[5][1][9]=3278; db[5][4][0]=3278; db[5][5][1]=3278; db[5][6][1]=3278; db[5][6][7]=3278; db[5][7][0]=3278; db[5][7][1]=3278; db[5][8][5]=3278; db[5][8][6]=3278; db[6][0][3]=3278; db[6][0][6]=3278; db[6][0][7]=3278; db[6][0][9]=3278; db[6][1][0]=3278; db[6][1][3]=3278; db[6][1][4]=3278; db[6][1][6]=3278; db[6][1][7]=3278; db[6][3][1]=3278; db[6][4][6]=3278; db[6][4][7]=3278; db[6][4][9]=3278; db[6][7][8]=3278; db[7][0][3]=3278; db[7][0][4]=3278; db[7][0][5]=3278; db[7][0][6]=3278; db[7][1][6]=3278; db[7][1][7]=3278; db[7][1][8]=3278; db[7][2][4]=3278; db[7][2][7]=3278; db[7][3][2]=3278; db[7][3][4]=3278; db[7][4][0]=3278; db[7][5][4]=3278; db[7][5][7]=3278; db[7][7][0]=3278; db[7][7][2]=3278; db[7][7][4]=3278; db[7][8][1]=3278; db[7][8][6]=3278; db[8][0][2]=3278; db[8][0][3]=3278; db[8][0][4]=3278; db[8][1][0]=3278; db[8][1][3]=3278; db[8][1][4]=3278; db[8][1][9]=3278; db[8][2][8]=3278; db[8][3][5]=3278; db[8][4][3]=3278; db[8][4][5]=3278; db[8][4][8]=3278; db[8][5][6]=3278; db[8][5][7]=3278; db[8][5][9]=3278; db[8][6][0]=3278; db[8][6][2]=3278; db[8][6][3]=3278; db[8][6][5]=3278; db[8][7][6]=3278; db[8][7][8]=3278; db[9][0][4]=3278; db[9][0][5]=3278; db[9][0][8]=3278; db[9][1][0]=3278; db[9][1][2]=3278; db[9][1][4]=3278; db[9][1][7]=3278; db[9][1][9]=3278; db[9][3][7]=3278; db[9][4][1]=3278; db[9][4][7]=3278; db[9][5][4]=3278; db[9][5][9]=3278; db[9][7][3]=3278; db[9][7][8]=3278; db[9][8][0]=3278; db[9][8][9]=3278; db[2][0][4]=2368;/*Central Time Zone */ db[2][0][5]=2368; db[2][1][0]=2368; db[2][1][4]=2368; db[2][1][7]=2368; db[2][1][8]=2368; db[2][2][4]=2368; db[2][2][5]=2368; db[2][2][8]=2368; db[2][5][1]=2368; db[2][5][4]=2368; db[2][5][6]=2368; db[2][6][2]=2368; db[2][7][0]=2368; db[2][8][1]=2368; db[3][0][9]=2368; db[3][1][2]=2368; db[3][1][4]=2368; db[3][1][6]=2368; db[3][1][8]=2368; db[3][1][9]=2368; db[3][2][0]=2368; db[3][2][5]=2368; db[3][3][4]=2368; db[3][3][7]=2368; db[3][6][1]=2368; db[4][0][2]=2368; db[4][0][5]=2368; db[4][0][9]=2368; db[4][1][4]=2368; db[4][1][7]=2368; db[4][3][0]=2368; db[4][3][2]=2368; db[4][6][9]=2368; db[4][7][9]=2368; db[5][0][1]=2368; db[5][0][4]=2368; db[5][0][7]=2368; db[5][1][2]=2368; db[5][1][5]=2368; db[5][6][3]=2368; db[5][7][3]=2368; db[5][8][0]=2368; db[6][0][1]=2368; db[6][0][8]=2368; db[6][1][2]=2368; db[6][1][5]=2368; db[6][1][8]=2368; db[6][3][0]=2368; db[6][3][6]=2368; db[6][4][1]=2368; db[6][5][1]=2368; db[6][6][0]=2368; db[6][6][2]=2368; db[6][8][2]=2368; db[7][0][8]=2368; db[7][1][2]=2368; db[7][1][3]=2368; db[7][1][5]=2368; db[7][3][1]=2368; db[7][6][3]=2368; db[7][6][9]=2368; db[7][7][3]=2368; db[8][0][6]=2368; db[8][1][5]=2368; db[8][1][6]=2368; db[8][1][7]=2368; db[8][3][0]=2368; db[8][3][2]=2368; db[8][4][7]=2368; db[8][7][0]=2368; db[9][0][1]=2368; db[9][0][3]=2368; db[9][1][3]=2368; db[9][1][8]=2368; db[9][2][0]=2368; db[9][3][1]=2368; db[9][3][6]=2368; db[9][4][0]=2368; db[9][5][2]=2368; db[9][5][6]=2368; db[9][7][2]=2368; db[9][7][9]=2368; db[9][8][5]=2368; db[3][0][3]=6686;/*Mountain Time Zone */ db[3][0][7]=6686; db[3][8][5]=6686; db[4][0][3]=6686; db[4][0][6]=6686; db[4][3][5]=6686; db[5][0][5]=6686; db[7][1][9]=6686; db[7][2][0]=6686; db[7][8][0]=6686; db[8][0][1]=6686; db[9][7][0]=6686; db[2][0][6]=7224; /*Pacific Time Zone*/ db[2][0][9]=7224; db[2][1][3]=7224; db[2][5][3]=7224; db[3][1][0]=7224; db[3][2][3]=7224; db[3][6][0]=7224; db[4][0][8]=7224; db[4][1][5]=7224; db[4][2][5]=7224; db[5][0][3]=7224; db[5][0][9]=7224; db[5][1][0]=7224; db[5][3][0]=7224; db[5][5][9]=7224; db[5][6][2]=7224; db[6][0][4]=7224; db[6][1][9]=7224; db[6][2][6]=7224; db[6][5][0]=7224; db[6][6][1]=7224; db[7][0][2]=7224; db[7][0][7]=7224; db[7][1][4]=7224; db[7][6][0]=7224; db[7][7][5]=7224; db[7][7][8]=7224; db[8][0][5]=7224; db[8][1][8]=7224; db[8][3][1]=7224; db[8][5][8]=7224; db[9][0][9]=7224; db[9][1][6]=7224; db[9][2][5]=7224; db[9][4][9]=7224; db[9][5][1]=7224; db[9][7][1]=7224; db[7][6][5]=2389;/*central and eastern time zone*/ db[2][1][9]=2389; db[2][6][0]=2389; db[3][1][7]=2389; db[4][2][3]=2389; db[5][7][4]=2389; db[8][0][7]=2389; db[8][1][2]=2389; db[8][5][0]=2389; db[9][0][6]=2389; db[6][2][0]=2689;/*Central & Mountain Time Zones*/ db[3][0][6]=2689; db[3][0][8]=2689; db[6][0][5]=2689; db[7][0][1]=6289;/*Mountain & Central Time Zones*/ db[7][8][5]=6289; db[9][1][5]=6289; db[2][0][8]=6789;/*Mountain & Pacific Time Zones*/ db[2][5][0]=6789; db[4][8][0]=6789; db[5][2][0]=6789; db[5][4][1]=6789; db[6][0][2]=6789; db[6][2][3]=6789; db[9][2][8]=6789; db[9][0][7]=2289;/*Aleutian & Alaskan Time Zones*/ db[2][4][2]=2852;/*Atlantic Time Zone */ db[2][4][6]=2852; db[2][6][4]=2852; db[2][6][8]=2852; db[2][8][4]=2852; db[3][4][0]=2852; db[4][4][1]=2852; db[4][7][3]=2852; db[5][0][6]=2852; db[6][6][4]=2852; db[7][5][8]=2852; db[7][6][7]=2852; db[7][8][4]=2852; db[7][8][7]=2852; db[8][0][9]=2852; db[8][2][9]=2852; db[8][6][8]=2852; db[8][6][9]=2852; db[9][0][2]=2852; db[9][3][9]=2852; db[8][0][8]=4292; db[7][0][9]=6389;/*Newfoundland Time Zone*/ db[8][6][7]=7289;/*Pacific through Alaskan */ db[6][8][4]=7789;/*Samoan Standard Time Zone */ }
I am using dev-c++ ver 4.9.9.2 to develop this program.
![]() |
Similar Threads
- how to print out an array in a message box (Java)
- Array problem (Java)
- Messy array things. (C++)
- Help : Pointers to array of class objects . (C++)
- Array troubles? (C++)
- Run-time Error when printing Array Contents. (C)
- Problem in finding out an array (Java)
- help with first and second problem (C++)
Other Threads in the C Forum
- Previous Thread: not for repeat cards again!
- Next Thread: Hey!! Need Help With A Pseudocode Problem, Help Please
| Thread Tools | Search this Thread |
* ansi api array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile creafecopyofanytypeoffileinc createcopyoffile createprocess() database dynamic execv fflush fgets file floatingpointvalidation fork forloop frequency function getlogicaldrivestrin givemetehcodez grade graphics gtkwinlinux histogram homework i/o ide inches include infiniteloop initialization input interest intmain() iso keyboard km license linked linkedlist linux list looping loopinsideloop. lowest matrix microsoft mysql oddnumber open opendocumentformat openwebfoundation pdf pointer pointers posix power program programming pyramidusingturboccodes radix read recursion recv recvblocked reversing scanf scheduling segmentationfault send sequential shape single socketprogramming stack standard strchr string suggestions test threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi






