By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,190 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,190 IT Pros & Developers. It's quick & easy.

access violation??

P: 4
hi
i'm getting access violation to my code..
what might be the problem??
plz help me...

//my code...

#include<stdio.h>
void main()
{
int prneqldrn(int a[],int b[]);
int tmp;
int c[]={1,1,1,1,0,0,1,0,0,1,0,1,0,0,1,1,1,0};
int d[]={1,1,1,1,0,0,0,1,0,1,0,1};
tmp=prneqldrn(c,d);
//printf("%d",tmp);


}


int prneqldrn(int datain[],int presntadd[])
{

int prn_t[3], drn_t[3];
int i,j,temp[3],t;

for (i=6;i<=9;i++)
{
j=i-6;
drn_t[j] = datain [i];
}
for (i=6;i<=9;i++)
{
j=i-6;
prn_t[j] = presntadd[i];
}
for(i=0;i<=3;i++)
{
temp[i]=(drn_t[i]==prn_t[i])?1:0;
}
t=(temp[0]&temp[1]&temp[2]&temp[3]);

return t;
}
Jun 13 '07 #1
Share this Question
Share on Google+
6 Replies


100+
P: 208
hi
i'm getting access violation to my code..
what might be the problem??
plz help me...

//my code...
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. void main()
  3. {
  4.     int prneqldrn(int a[],int b[]);
  5.     int tmp;
  6.     int c[]={1,1,1,1,0,0,1,0,0,1,0,1,0,0,1,1,1,0};
  7.     int d[]={1,1,1,1,0,0,0,1,0,1,0,1};
  8.     tmp=prneqldrn(c,d);
  9.     //printf("%d",tmp);
  10.  
  11.  
  12. }
  13.  
  14.  
  15. int prneqldrn(int datain[],int presntadd[])
  16. {
  17.  
  18.     int prn_t[3], drn_t[3];
  19.     int i,j,temp[3],t;
  20.  
  21.     for (i=6;i<=9;i++)
  22.         {
  23.             j=i-6;
  24.             drn_t[j] = datain [i];
  25.         }
  26.     for (i=6;i<=9;i++)
  27.     {
  28.         j=i-6;
  29.         prn_t[j] = presntadd[i];
  30.     }
  31.     for(i=0;i<=3;i++)
  32.     {
  33.         temp[i]=(drn_t[i]==prn_t[i])?1:0;
  34.     }
  35.     t=(temp[0]&temp[1]&temp[2]&temp[3]);
  36.  
  37.     return t;
  38. }
Firstly Please enclose your code in [code] [/ CODE] brackets
Second. When I run this I don't get any access violation errors. The function returns 0.
Jun 13 '07 #2

P: 94
if you comment out this ->
Expand|Select|Wrap|Line Numbers
  1. t=(temp[0]&temp[1]&temp[2]&temp[3]);
then it compiles

Go look at that
Jun 13 '07 #3

P: 4
Firstly Please enclose your code in [code] [/ CODE] brackets
Second. When I run this I don't get any access violation errors. The function returns 0.
hi,
thanq for ur quick response...
i tried the compilation in turboc++.it worked well without any problem..
but in vc++ its giving problem...
someone told it is b'coz of the s/w (vc++) which has n't been installed properly....
anyway thanx a lot..
Jun 13 '07 #4

P: 4
if you comment out this ->
Expand|Select|Wrap|Line Numbers
  1. t=(temp[0]&temp[1]&temp[2]&temp[3]);
then it compiles

Go look at that
hi,
thanq for ur quick response...
i tried the compilation in turboc++.it worked well without any problem..
but in vc++ its giving problem...
someone told it is b'coz of the s/w (vc++) which has n't been installed properly....
anyway thanx a lot..
Jun 13 '07 #5

weaknessforcats
Expert Mod 5K+
P: 9,197
Here's part of your problem:
Expand|Select|Wrap|Line Numbers
  1. prneqldrn(int datain[],int presntadd[])
  2. {
  3.  
  4. int prn_t[3], drn_t[3];
  5. int i,j,temp[3],t;
  6.  
  7. for (i=6;i<=9;i++)
  8. {
  9. j=i-6;
  10. drn_t[j] = datain [i];     <------
  11. }
  12. etc...
  13.  
drn_t is an array of 3 elements.
drn_t[j] cannot be larger than 2. Otherwise, you get your error.

i = 6 then j = 0
i = 7 then j = 1
i = 8 then j = 2
i = 9 then j = 3 < BOOM!
Jun 13 '07 #6

P: 4
ya ...
u r correct..
i've changed that one and i got the output...
Jun 14 '07 #7

Post your reply

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