| | |
Help - Problem with array
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
I compiled and ran the program -- I didn't get any runtime errors, but I only entered a couple time zones.
Your program is more than a little confusing. why are you putting just one character at a time in its own array element of query[] ? For example, if I enter 123 <Enter> the program puts query[0] = '1', query[1] = '2' and query[2] = '3'. Then if I enter 234 <Enter> the program puts query[3] = '2', query[4] = '3' and query[5] = '4'. At this point it has
query[0] = '1'
query[1] = '2'
query[2] = '3'
query[3] = '2'
query[4] = '3'
query[5] = '4'
Note that the above contain the ascii values for the numbers I entered, not the binary values. The letter '1' is NOT the same as the number 1. (google for "ascii chart" and you will discover why)
Next you extract the three values from the above array. '1', '2' and '3' are the first thee. Then you attempt to use them as the index into the db array. But db array has a maximum of 9 for each dimension, and you are attempting to access '1' (49 decimal).
You have an array overflow problem -- attemtping to access elements out of bounds. To correct this you need to convert the letters to binary. One way to do that is like this:
Finally, you need to put a break statement at the end of each case.
Your program is more than a little confusing. why are you putting just one character at a time in its own array element of query[] ? For example, if I enter 123 <Enter> the program puts query[0] = '1', query[1] = '2' and query[2] = '3'. Then if I enter 234 <Enter> the program puts query[3] = '2', query[4] = '3' and query[5] = '4'. At this point it has
query[0] = '1'
query[1] = '2'
query[2] = '3'
query[3] = '2'
query[4] = '3'
query[5] = '4'
Note that the above contain the ascii values for the numbers I entered, not the binary values. The letter '1' is NOT the same as the number 1. (google for "ascii chart" and you will discover why)
Next you extract the three values from the above array. '1', '2' and '3' are the first thee. Then you attempt to use them as the index into the db array. But db array has a maximum of 9 for each dimension, and you are attempting to access '1' (49 decimal).
You have an array overflow problem -- attemtping to access elements out of bounds. To correct this you need to convert the letters to binary. One way to do that is like this:
C Syntax (Toggle Plain Text)
hundred=filtered[i] - '0'; ten=filtered[i+1] - '0'; one=filtered[i+2] - '0';
Finally, you need to put a break statement at the end of each case.
Last edited by Ancient Dragon; Jan 2nd, 2007 at 5:51 am.
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.
![]() |
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 |
#include adobe api array arrays asterisks binarysearch calculate char cm copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic feet fflush fgets file fork forloop framework frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o include incrementoperators input interest kernel kilometer linked linkedlist linux linuxsegmentationfault list lists locate logical_drives loopinsideloop. match matrix meter microsoft motherboard mqqueue multi mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling scripting segmentationfault sequential shape socket socketprograming stack standard string strings systemcall testing turboc unix user voidmain() wab windows.h






