access violation??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • radhapurnima
    New Member
    • Jun 2007
    • 4

    access violation??

    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;
    }
  • Silent1Mezzo
    New Member
    • Feb 2007
    • 208

    #2
    Originally posted by radhapurnima
    hi
    i'm getting access violation to my code..
    what might be the problem??
    plz help me...

    //my code...
    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;
    }
    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.

    Comment

    • Extremist
      New Member
      • Jan 2007
      • 94

      #3
      if you comment out this ->
      Code:
      t=(temp[0]&temp[1]&temp[2]&temp[3]);
      then it compiles

      Go look at that

      Comment

      • radhapurnima
        New Member
        • Jun 2007
        • 4

        #4
        Originally posted by Silent1Mezzo
        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..

        Comment

        • radhapurnima
          New Member
          • Jun 2007
          • 4

          #5
          Originally posted by Extremist
          if you comment out this ->
          Code:
          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..

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            Here's part of your problem:
            [code=cpp]
            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]; <------
            }
            etc...
            [/code]

            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!

            Comment

            • radhapurnima
              New Member
              • Jun 2007
              • 4

              #7
              ya ...
              u r correct..
              i've changed that one and i got the output...

              Comment

              Working...