|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
Access violation or not Here's my program: Description: The program asks you to enter a number in decimal, and then it begins to divide that number by number basis. It begins to divide and we stop when the quotient is equal to 0, while setting the table in the result, and displaying so reversed, we get the number correctly. It has decremented the counter, because the last element of the array containing n elements is indexed (n-1). Code: #include <stdio.h> int main() { int base[14][20],counter[14],rest=0,i,division,decimal; for(i=0;i<=14;i++) counter[i] = 0; printf("Enter a number in decimal :\n"); scanf("%d",&decimal); for(i=2;i<=16;i++) { division = decimal; while(division != 0) { rest = division%i; division = division/i; base[i-2][counter[i-2]++] = rest; } counter[i-2]--; //last element of tab is indexed n-1 printf("\nBase %d : ",i); while(counter[i-2] >= 0) { if (base[i-2][counter[i-2]] >= 10) printf("%c",base[i-2][counter[i-2]--]+55); //10+55 = 65(A) else printf("%d",base[i-2][counter[i-2]--]); } } printf("\n"); system("pause"); return 0; } Can you tell me where is the problem, though I fumbled with the debugger in vain? |
#2
| |||
| |||
Re: Access violation or not Code: #include <stdio.h> int main() { int base[14][20],counter[14],rest=0,i,division,decimal; for(i=0;i<=14;i++) counter[i] = 0; printf("Enter a number in decimal :\n" ); scanf("%d",&decimal); for(i=2;i<=16;i++) { division = decimal; while(division != 0) { rest = division%i; division = division/i; base[i-2][counter[i-2]++] = rest; } counter[i-2]--; //last element of tab is indexed n-1 printf("\nBase %d : ",i); while(counter[i-2] >= 0) { if (base[i-2][counter[i-2]] >= 10) printf("%c",base[i-2][counter[i-2]--]+55); //10+55 = 65(A) else printf("%d",base[i-2][counter[i-2]--]); } } printf("\n" ); system("pause" ); return 0; } |
#3
| |||
| |||
Re: Access violation or not You iterates in line 9 from 2 to 16. Then you'll tap in counter [i - 2]. Counter is an array of 14. So when you pass the last time you tap in meter [14], the 15th box.
__________________ The FIFA Manager 2009 PC Game |
#4
| |||
| |||
Re: Access violation or not Ah yes, 16-2+1 that is 15, then base [15] [20] and counter [15]! Thank you very much to two of you! |
![]() |
|
Tags: access violation, c language |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Skype 4.2.0.169 access violation | Shin-Chen | Technology & Internet | 6 | 12-08-2010 11:03 PM |
PHP has encountered an Access Violation at 01B9AD16 | cornto | Software Development | 4 | 02-01-2010 12:49 PM |
Access violation ... in module ntdll.dll | James O''''Reilly | Vista Help | 4 | 15-07-2009 09:54 PM |
0xC0000005 Access Violation Error | Farley | Operating Systems | 5 | 14-03-2009 09:21 AM |
Access violation at address 0000702b | Aliya | Operating Systems | 5 | 05-01-2009 10:25 AM |