Passing an array by reference in C?

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4

47 Replies - 2338 Views - Last Post: 09 October 2017 - 07:57 AM Rate Topic: -----

#16 thaus_15  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 53
  • Joined: 09-May 17

Re: Passing an array by reference in C?

Posted 31 August 2017 - 05:16 AM

Still, i am getting warning messages. Please sort it out. It will be grateful.

#include <stdio.h>
#include <math.h>
 
#define COL 204
#define COL_P 2
#define ROWS_P 1020
 
int codecheck(int col,int col_p,int rows_p,int (*h)[2],int x[])
{	int i,j,m,f; //flags
	int sum = 0;
	int y[COL];
	
	for (i=0;i<COL;i++)
	y[i]=0;
	m=1;
	f=-1;
	for(i=0;i<rows_p;)							 
	{			
		for(j=0;j<rows_p;j++)
		{
			if(h[j][0]==m)
			{		
				y[m]=y[m] + x[h[j][1]-1];
					f++;
			}
		}
		y[m]=y[m]%2;
		m=m+1;
		i=f+1;
	}
 
	for (i = 0; i < COL; ++i) 
		{
			sum =sum+ y[i];
		}
	if (sum == 0) 
		{
			return 1;
		}
	else
		{	
			return -1;
		}
				
}
 
int codesum (int y[],int col)
{
    int sum=0;
    for(int i=0;i<COL;i++)
        sum+=y[i];
    //cout<< "sum="<< sum<<endl;
    if(sum>0)
        return 0;
    else
        return 1;
}
 
void SPADecoder(int rows_p, double LLR[], int (*h)[2], double LLR_ret[], double L_ch[],  double L_dec[], int y[], int z, int col)
{
    double temp;
	int col_p;
    int i,j,k;
    for(i=0;i<rows_p;i++)
    {
        temp=1;
        for(j=0;j<rows_p;j++)
        {
            if(j!=i && h[j][0]==h[i][0])
            {
                temp=temp * tanhf(LLR[j]/2);
            }
        }
								
								
        LLR_ret[i] = log((1 + temp)/(1 - temp));     // lower and upper bounding the LLR
								
        if(LLR_ret[i] > 40)
        {
            LLR_ret[i]=40;
        }
        else if(LLR_ret[i]<-40)
        {
            LLR_ret[i]=-40;
        }
        
    }
    
    for(i=0;i<COL;i++)							// L_dec array used to decide the value of each bit of codeword here it is initalized to LLr value received from channel
    {
        L_dec[i]=L_ch[i];
    }
    
    
    for(i=1;i<col+1;i++)						// LLR values received by the variable nodes are added and stored in L_dec for decision making
    {
        for(j=0;j<rows_p;j++)
        {
            if(h[j][1]==i)
            {
                L_dec[i-1]=L_dec[i-1]+LLR_ret[j];
            }
            
        }
        
        if(L_dec[i-1]<=0)						// decision about the bit values of the received codeword is done her and stored in Y.
        {
            y[i-1]=1;
        }
        else
        {
            y[i-1]=0;
        }
        
    }
    
    
    //z = codesum(y,col);
    z=codecheck(col, col_p,rows_p,h,y); // checking whether the decoded codeword is all zero or not
    
    if(z==1)								// if decoded perfectly exit the deoding loop
    {
        return ;
    }
    // updating LLR values on variable nodes side for each variable and check node
    for(i=0;i<rows_p;i++)
    {
        temp=0;
        for(j=0;j<rows_p;j++)
        {
            if(j!=i && h[j][1]==h[i][1])
            {
                temp=temp + LLR_ret[j];
                k=h[i][1];
                
            }
        }
        LLR[i] = temp+L_ch[k-1];
    }
 
}
 
int main()
{
    
    
	// flags and counters
	int z,i,j,N,k,ber_count,looping,t,sum;
    float d=1;
	float rate=0.5;
	int rows_p,col_p;
	int col;			// iterations gives the maximum number of time the decoder is run for each value of SNR
 
	double var,snr;
	double temp; 								
	
    float y[COL],x[COL],noise[COL];  // "x" will be used as a codeword and "y" is received codeword.
    double L_ch[COL],L_dec[COL];    //holds LLR values given by the channel
	double LLR[ROWS_P],LLR_ret[ROWS_P];					//hold updated LLR values at variable node and check node respectively
 
   int  ret,row=0;
 
    
int h[ROWS_P][COL_P]={{1,1},{1,18},{1,27},{1,82},{1,102},{1,103},{1,130},{1,177},{1,190},{1,203},{2,2},{2,15},{2,75},{2,80},{2,86},{2,104},{2,121},{2,141},{2,144},{2,191},{3,3},{3,31},{3,32},{3,42},{3,101},{3,105},{3,153},{3,159},{3,178},{3,199},{4,4},{4,37},{4,71},{4,75},{4,85},{4,106},{4,111},{4,114},{4,127},{4,164},{5,5},{5,17},{5,42},{5,72},{5,87},{5,107},{5,141},{5,158},{5,193},{5,197},{6,4},{6,6},{6,17},{6,78},{6,102},{6,108},{6,162},{6,165},{6,167},{6,174},{7,7},{7,23},{7,73},{7,80},{7,83},{7,109},{7,118},{7,168},{7,177},{7,178},{8,8},{8,33},{8,37},{8,73},{8,100},{8,110},{8,156},{8,173},{8,192},{8,197},{9,9},{9,40},{9,41},{9,88},{9,92},{9,103},{9,111},{9,173},{9,181},{9,199},{10,10},{10,14},{10,23},{10,53},{10,93},{10,107},{10,112},{10,137},{10,167},{10,175},{11,11},{11,19},{11,26},{11,28},{11,88},{11,110},{11,113},{11,116},{11,170},{11,191},{12,1},{12,12},{12,25},{12,86},{12,97},{12,108},{12,114},{12,124},{12,161},{12,192},{13,4},{13,13},{13,33},{13,34},{13,50},{13,115},{13,137},{13,140},{13,146},{13,160},{14,14},{14,31},{14,40},{14,58},{14,95},{14,116},{14,121},{14,166},{14,174},{14,203},{15,15},{15,68},{15,70},{15,87},{15,101},{15,109},{15,113},{15,117},{15,165},{15,180},{16,4},{16,16},{16,59},{16,67},{16,92},{16,118},{16,125},{16,131},{16,138},{16,151},{17,15},{17,17},{17,44},{17,71},{17,73},{17,119},{17,161},{17,190},{17,194},{17,198},{18,18},{18,47},{18,62},{18,85},{18,93},{18,120},{18,122},{18,125},{18,146},{18,181},{19,19},{19,22},{19,23},{19,37},{19,57},{19,121},{19,126},{19,130},{19,131},{19,143},{20,1},{20,20},{20,50},{20,51},{20,99},{20,106},{20,122},{20,169},{20,179},{20,200},{21,21},{21,32},{21,62},{21,72},{21,98},{21,123},{21,126},{21,154},{21,168},{21,204},{22,22},{22,31},{22,44},{22,89},{22,98},{22,124},{22,141},{22,160},{22,169},{22,176},{23,23},{23,32},{23,61},{23,65},{23,99},{23,125},{23,132},{23,133},{23,147},{23,152},{24,16},{24,24},{24,42},{24,73},{24,77},{24,126},{24,142},{24,145},{24,146},{24,147},{25,5},{25,24},{25,25},{25,55},{25,67},{25,127},{25,133},{25,165},{25,178},{25,185},{26,10},{26,26},{26,27},{26,40},{26,85},{26,128},{26,147},{26,155},{26,160},{26,200},{27,22},{27,27},{27,42},{27,50},{27,74},{27,108},{27,129},{27,154},{27,170},{27,195},{28,2},{28,28},{28,63},{28,67},{28,94},{28,130},{28,150},{28,171},{28,187},{28,192},{29,29},{29,48},{29,69},{29,79},{29,90},{29,116},{29,131},{29,159},{29,176},{29,200},{30,7},{30,30},{30,53},{30,58},{30,94},{30,127},{30,132},{30,140},{30,162},{30,189},{31,29},{31,31},{31,64},{31,77},{31,94},{31,117},{31,133},{31,167},{31,183},{31,190},{32,20},{32,30},{32,32},{32,74},{32,78},{32,115},{32,134},{32,151},{32,181},{32,194},{33,11},{33,33},{33,47},{33,76},{33,81},{33,109},{33,135},{33,154},{33,155},{33,179},{34,2},{34,7},{34,34},{34,71},{34,76},{34,136},{34,138},{34,159},{34,182},{34,183},{35,27},{35,29},{35,35},{35,60},{35,86},{35,123},{35,137},{35,149},{35,166},{35,189},{36,17},{36,35},{36,36},{36,48},{36,100},{36,138},{36,139},{36,146},{36,163},{36,168},{37,5},{37,34},{37,37},{37,38},{37,69},{37,117},{37,139},{37,145},{37,169},{37,203},{38,38},{38,56},{38,76},{38,92},{38,101},{38,106},{38,123},{38,140},{38,161},{38,170},{39,39},{39,41},{39,60},{39,76},{39,78},{39,125},{39,141},{39,142},{39,175},{39,198},{40,2},{40,35},{40,40},{40,43},{40,93},{40,114},{40,135},{40,142},{40,148},{40,158},{41,1},{41,2},{41,13},{41,41},{41,59},{41,109},{41,119},{41,132},{41,143},{41,157},{42,11},{42,42},{42,43},{42,92},{42,95},{42,115},{42,117},{42,144},{42,156},{42,204},{43,7},{43,9},{43,43},{43,45},{43,56},{43,122},{43,145},{43,192},{43,194},{43,201},{44,10},{44,44},{44,75},{44,83},{44,95},{44,110},{44,135},{44,146},{44,157},{44,180},{45,45},{45,63},{45,79},{45,81},{45,97},{45,127},{45,139},{45,147},{45,148},{45,195},{46,34},{46,46},{46,61},{46,66},{46,77},{46,105},{46,144},{46,148},{46,197},{46,201},{47,14},{47,20},{47,46},{47,47},{47,83},{47,124},{47,128},{47,132},{47,149},{47,159},{48,8},{48,13},{48,26},{48,48},{48,62},{48,149},{48,150},{48,174},{48,193},{48,195},{49,15},{49,21},{49,25},{49,49},{49,51},{49,145},{49,149},{49,151},{49,177},{49,188},{50,8},{50,49},{50,50},{50,54},{50,89},{50,105},{50,126},{50,152},{50,164},{50,165},{51,43},{51,51},{51,66},{51,68},{51,91},{51,131},{51,133},{51,153},{51,187},{51,189},{52,1},{52,39},{52,45},{52,52},{52,54},{52,110},{52,140},{52,150},{52,154},{52,163},{53,8},{53,53},{53,60},{53,64},{53,90},{53,138},{53,155},{53,157},{53,194},{53,204},{54,12},{54,28},{54,54},{54,60},{54,82},{54,112},{54,139},{54,151},{54,156},{54,183},{55,3},{55,17},{55,37},{55,55},{55,99},{55,112},{55,148},{55,157},{55,172},{55,189},{56,20},{56,31},{56,56},{56,80},{56,91},{56,152},{56,156},{56,158},{56,162},{56,180},{57,28},{57,57},{57,66},{57,81},{57,89},{57,134},{57,137},{57,159},{57,172},{57,196},{58,5},{58,58},{58,70},{58,78},{58,91},{58,118},{58,149},{58,154},{58,160},{58,201},{59,18},{59,24},{59,59},{59,88},{59,96},{59,150},{59,152},{59,161},{59,179},{59,183},{60,21},{60,38},{60,55},{60,59},{60,60},{60,162},{60,176},{60,187},{60,190},{60,197},{61,61},{61,69},{61,74},{61,93},{61,101},{61,111},{61,128},{61,163},{61,193},{61,196},{62,6},{62,7},{62,35},{62,62},{62,96},{62,103},{62,113},{62,129},{62,164},{62,200},{63,16},{63,27},{63,44},{63,63},{63,88},{63,121},{63,134},{63,165},{63,175},{63,188},{64,4},{64,26},{64,64},{64,79},{64,84},{64,119},{64,134},{64,136},{64,166},{64,168},{65,12},{65,13},{65,52},{65,57},{65,65},{65,106},{65,138},{65,142},{65,167},{65,176},{66,24},{66,30},{66,52},{66,66},{66,102},{66,112},{66,117},{66,122},{66,135},{66,168},{67,6},{67,57},{67,67},{67,85},{67,97},{67,140},{67,169},{67,182},{67,184},{67,186},{68,6},{68,58},{68,68},{68,71},{68,90},{68,134},{68,143},{68,145},{68,152},{68,170},{69,54},{69,57},{69,59},{69,69},{69,77},{69,103},{69,104},{69,114},{69,136},{69,171},{70,19},{70,24},{70,56},{70,70},{70,100},{70,105},{70,114},{70,128},{70,129},{70,172},{71,14},{71,52},{71,63},{71,70},{71,71},{71,120},{71,169},{71,173},{71,178},{71,196},{72,11},{72,25},{72,39},{72,66},{72,72},{72,120},{72,130},{72,132},{72,174},{72,199},{73,48},{73,49},{73,64},{73,73},{73,98},{73,111},{73,175},{73,179},{73,201},{73,202},{74,9},{74,15},{74,58},{74,74},{74,84},{74,107},{74,120},{74,135},{74,164},{74,176},{75,28},{75,41},{75,70},{75,75},{75,96},{75,133},{75,155},{75,166},{75,177},{75,202},{76,26},{76,45},{76,65},{76,76},{76,94},{76,144},{76,158},{76,172},{76,178},{76,203},{77,10},{77,13},{77,77},{77,84},{77,87},{77,127},{77,151},{77,163},{77,179},{77,191},{78,49},{78,55},{78,65},{78,78},{78,90},{78,122},{78,130},{78,139},{78,180},{78,182},{79,33},{79,43},{79,67},{79,79},{79,99},{79,123},{79,141},{79,181},{79,188},{79,202},{80,18},{80,19},{80,35},{80,46},{80,80},{80,153},{80,167},{80,182},{80,188},{80,193},{81,9},{81,16},{81,36},{81,55},{81,81},{81,143},{81,160},{81,183},{81,186},{81,191},{82,10},{82,11},{82,79},{82,82},{82,96},{82,108},{82,111},{82,126},{82,172},{82,184},{83,12},{83,36},{83,69},{83,83},{83,87},{83,148},{83,174},{83,185},{83,202},{83,204},{84,45},{84,47},{84,48},{84,75},{84,84},{84,108},{84,123},{84,142},{84,153},{84,186},{85,9},{85,46},{85,53},{85,54},{85,85},{85,115},{85,121},{85,129},{85,177},{85,187},{86,22},{86,64},{86,83},{86,86},{86,91},{86,107},{86,116},{86,171},{86,188},{86,199},{87,8},{87,22},{87,61},{87,81},{87,87},{87,104},{87,120},{87,182},{87,189},{87,198},{88,32},{88,33},{88,39},{88,51},{88,88},{88,129},{88,143},{88,171},{88,180},{88,190},{89,3},{89,21},{89,52},{89,89},{89,100},{89,103},{89,109},{89,115},{89,125},{89,191},{90,20},{90,40},{90,44},{90,61},{90,90},{90,118},{90,137},{90,153},{90,184},{90,192},{91,6},{91,23},{91,29},{91,84},{91,91},{91,144},{91,155},{91,173},{91,185},{91,193},{92,14},{92,49},{92,72},{92,92},{92,102},{92,147},{92,171},{92,185},{92,186},{92,194},{93,5},{93,21},{93,29},{93,65},{93,93},{93,105},{93,110},{93,119},{93,184},{93,195},{94,39},{94,80},{94,82},{94,94},{94,98},{94,107},{94,113},{94,131},{94,166},{94,196},{95,30},{95,47},{95,50},{95,63},{95,95},{95,104},{95,118},{95,161},{95,163},{95,197},{96,25},{96,34},{96,56},{96,68},{96,96},{96,116},{96,181},{96,186},{96,196},{96,198},{97,36},{97,38},{97,46},{97,89},{97,97},{97,113},{97,136},{97,150},{97,157},{97,199},{98,3},{98,12},{98,18},{98,30},{98,98},{98,136},{98,170},{98,187},{98,198},{98,200},{99,53},{99,62},{99,74},{99,97},{99,99},{99,104},{99,119},{99,156},{99,185},{99,201},{100,16},{100,68},{100,82},{100,95},{100,100},{100,106}};
 
                        for(looping=0;looping<10;looping++)
						{
							
                            SPADecoder(rows_p, LLR, h, LLR_ret, L_ch, L_dec, y, z, col);
							printf("%f\t", y[looping]);
						}
return 0;
	
}


Warning Messages
prog.c: In function 'main':
prog.c:169:78: warning: passing argument 7 of 'SPADecoder' from incompatible pointer type [-Wincompatible-pointer-types]
                             SPADecoder(rows_p, LLR, h, LLR_ret, L_ch, L_dec, y, z, col);
                                                                              ^
prog.c:59:6: note: expected 'int *' but argument is of type 'float *'
 void SPADecoder(int rows_p, double LLR[], int (*h)[2], double LLR_ret[], double L_ch[],  double L_dec[], int y[], int z, int col)

Was This Post Helpful? 0
  • +
  • -

#17 thaus_15  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 53
  • Joined: 09-May 17

Re: Passing an array by reference in C?

Posted 31 August 2017 - 05:22 AM

View Postthaus_15, on 31 August 2017 - 05:16 AM, said:

Still, i am getting warning messages. Please sort it out. It will be grateful.

#include <stdio.h>
#include <math.h>
 
#define COL 204
#define COL_P 2
#define ROWS_P 1020
 
int codecheck(int col,int col_p,int rows_p,int (*h)[2],int x[])
{	int i,j,m,f; //flags
	int sum = 0;
	int y[COL];
	
	for (i=0;i<COL;i++)
	y[i]=0;
	m=1;
	f=-1;
	for(i=0;i<rows_p;)							 
	{			
		for(j=0;j<rows_p;j++)
		{
			if(h[j][0]==m)
			{		
				y[m]=y[m] + x[h[j][1]-1];
					f++;
			}
		}
		y[m]=y[m]%2;
		m=m+1;
		i=f+1;
	}
 
	for (i = 0; i < COL; ++i) 
		{
			sum =sum+ y[i];
		}
	if (sum == 0) 
		{
			return 1;
		}
	else
		{	
			return -1;
		}
				
}
 
int codesum (int y[],int col)
{
    int sum=0;
    for(int i=0;i<COL;i++)
        sum+=y[i];
    //cout<< "sum="<< sum<<endl;
    if(sum>0)
        return 0;
    else
        return 1;
}
 
void SPADecoder(int rows_p, double LLR[], int (*h)[2], double LLR_ret[], double L_ch[],  double L_dec[], int y[], int z, int col)
{
    double temp;
	int col_p;
    int i,j,k;
    for(i=0;i<rows_p;i++)
    {
        temp=1;
        for(j=0;j<rows_p;j++)
        {
            if(j!=i && h[j][0]==h[i][0])
            {
                temp=temp * tanhf(LLR[j]/2);
            }
        }
								
								
        LLR_ret[i] = log((1 + temp)/(1 - temp));     // lower and upper bounding the LLR
								
        if(LLR_ret[i] > 40)
        {
            LLR_ret[i]=40;
        }
        else if(LLR_ret[i]<-40)
        {
            LLR_ret[i]=-40;
        }
        
    }
    
    for(i=0;i<COL;i++)							// L_dec array used to decide the value of each bit of codeword here it is initalized to LLr value received from channel
    {
        L_dec[i]=L_ch[i];
    }
    
    
    for(i=1;i<col+1;i++)						// LLR values received by the variable nodes are added and stored in L_dec for decision making
    {
        for(j=0;j<rows_p;j++)
        {
            if(h[j][1]==i)
            {
                L_dec[i-1]=L_dec[i-1]+LLR_ret[j];
            }
            
        }
        
        if(L_dec[i-1]<=0)						// decision about the bit values of the received codeword is done her and stored in Y.
        {
            y[i-1]=1;
        }
        else
        {
            y[i-1]=0;
        }
        
    }
    
    
    //z = codesum(y,col);
    z=codecheck(col, col_p,rows_p,h,y); // checking whether the decoded codeword is all zero or not
    
    if(z==1)								// if decoded perfectly exit the deoding loop
    {
        return ;
    }
    // updating LLR values on variable nodes side for each variable and check node
    for(i=0;i<rows_p;i++)
    {
        temp=0;
        for(j=0;j<rows_p;j++)
        {
            if(j!=i && h[j][1]==h[i][1])
            {
                temp=temp + LLR_ret[j];
                k=h[i][1];
                
            }
        }
        LLR[i] = temp+L_ch[k-1];
    }
 
}
 
int main()
{
    
    
	// flags and counters
	int z,i,j,N,k,ber_count,looping,t,sum;
    float d=1;
	float rate=0.5;
	int rows_p,col_p;
	int col;			// iterations gives the maximum number of time the decoder is run for each value of SNR
 
	double var,snr;
	double temp; 								
	
    float y[COL],x[COL],noise[COL];  // "x" will be used as a codeword and "y" is received codeword.
    double L_ch[COL],L_dec[COL];    //holds LLR values given by the channel
	double LLR[ROWS_P],LLR_ret[ROWS_P];					//hold updated LLR values at variable node and check node respectively
 
   int  ret,row=0;
 
    
int h[ROWS_P][COL_P]={{1,1},{1,18},{1,27},{1,82},{1,102},{1,103},{1,130},{1,177},{1,190},{1,203},{2,2},{2,15},{2,75},{2,80},{2,86},{2,104},{2,121},{2,141},{2,144},{2,191},{3,3},{3,31},{3,32},{3,42},{3,101},{3,105},{3,153},{3,159},{3,178},{3,199},{4,4},{4,37},{4,71},{4,75},{4,85},{4,106},{4,111},{4,114},{4,127},{4,164},{5,5},{5,17},{5,42},{5,72},{5,87},{5,107},{5,141},{5,158},{5,193},{5,197},{6,4},{6,6},{6,17},{6,78},{6,102},{6,108},{6,162},{6,165},{6,167},{6,174},{7,7},{7,23},{7,73},{7,80},{7,83},{7,109},{7,118},{7,168},{7,177},{7,178},{8,8},{8,33},{8,37},{8,73},{8,100},{8,110},{8,156},{8,173},{8,192},{8,197},{9,9},{9,40},{9,41},{9,88},{9,92},{9,103},{9,111},{9,173},{9,181},{9,199},{10,10},{10,14},{10,23},{10,53},{10,93},{10,107},{10,112},{10,137},{10,167},{10,175},{11,11},{11,19},{11,26},{11,28},{11,88},{11,110},{11,113},{11,116},{11,170},{11,191},{12,1},{12,12},{12,25},{12,86},{12,97},{12,108},{12,114},{12,124},{12,161},{12,192},{13,4},{13,13},{13,33},{13,34},{13,50},{13,115},{13,137},{13,140},{13,146},{13,160},{14,14},{14,31},{14,40},{14,58},{14,95},{14,116},{14,121},{14,166},{14,174},{14,203},{15,15},{15,68},{15,70},{15,87},{15,101},{15,109},{15,113},{15,117},{15,165},{15,180},{16,4},{16,16},{16,59},{16,67},{16,92},{16,118},{16,125},{16,131},{16,138},{16,151},{17,15},{17,17},{17,44},{17,71},{17,73},{17,119},{17,161},{17,190},{17,194},{17,198},{18,18},{18,47},{18,62},{18,85},{18,93},{18,120},{18,122},{18,125},{18,146},{18,181},{19,19},{19,22},{19,23},{19,37},{19,57},{19,121},{19,126},{19,130},{19,131},{19,143},{20,1},{20,20},{20,50},{20,51},{20,99},{20,106},{20,122},{20,169},{20,179},{20,200},{21,21},{21,32},{21,62},{21,72},{21,98},{21,123},{21,126},{21,154},{21,168},{21,204},{22,22},{22,31},{22,44},{22,89},{22,98},{22,124},{22,141},{22,160},{22,169},{22,176},{23,23},{23,32},{23,61},{23,65},{23,99},{23,125},{23,132},{23,133},{23,147},{23,152},{24,16},{24,24},{24,42},{24,73},{24,77},{24,126},{24,142},{24,145},{24,146},{24,147},{25,5},{25,24},{25,25},{25,55},{25,67},{25,127},{25,133},{25,165},{25,178},{25,185},{26,10},{26,26},{26,27},{26,40},{26,85},{26,128},{26,147},{26,155},{26,160},{26,200},{27,22},{27,27},{27,42},{27,50},{27,74},{27,108},{27,129},{27,154},{27,170},{27,195},{28,2},{28,28},{28,63},{28,67},{28,94},{28,130},{28,150},{28,171},{28,187},{28,192},{29,29},{29,48},{29,69},{29,79},{29,90},{29,116},{29,131},{29,159},{29,176},{29,200},{30,7},{30,30},{30,53},{30,58},{30,94},{30,127},{30,132},{30,140},{30,162},{30,189},{31,29},{31,31},{31,64},{31,77},{31,94},{31,117},{31,133},{31,167},{31,183},{31,190},{32,20},{32,30},{32,32},{32,74},{32,78},{32,115},{32,134},{32,151},{32,181},{32,194},{33,11},{33,33},{33,47},{33,76},{33,81},{33,109},{33,135},{33,154},{33,155},{33,179},{34,2},{34,7},{34,34},{34,71},{34,76},{34,136},{34,138},{34,159},{34,182},{34,183},{35,27},{35,29},{35,35},{35,60},{35,86},{35,123},{35,137},{35,149},{35,166},{35,189},{36,17},{36,35},{36,36},{36,48},{36,100},{36,138},{36,139},{36,146},{36,163},{36,168},{37,5},{37,34},{37,37},{37,38},{37,69},{37,117},{37,139},{37,145},{37,169},{37,203},{38,38},{38,56},{38,76},{38,92},{38,101},{38,106},{38,123},{38,140},{38,161},{38,170},{39,39},{39,41},{39,60},{39,76},{39,78},{39,125},{39,141},{39,142},{39,175},{39,198},{40,2},{40,35},{40,40},{40,43},{40,93},{40,114},{40,135},{40,142},{40,148},{40,158},{41,1},{41,2},{41,13},{41,41},{41,59},{41,109},{41,119},{41,132},{41,143},{41,157},{42,11},{42,42},{42,43},{42,92},{42,95},{42,115},{42,117},{42,144},{42,156},{42,204},{43,7},{43,9},{43,43},{43,45},{43,56},{43,122},{43,145},{43,192},{43,194},{43,201},{44,10},{44,44},{44,75},{44,83},{44,95},{44,110},{44,135},{44,146},{44,157},{44,180},{45,45},{45,63},{45,79},{45,81},{45,97},{45,127},{45,139},{45,147},{45,148},{45,195},{46,34},{46,46},{46,61},{46,66},{46,77},{46,105},{46,144},{46,148},{46,197},{46,201},{47,14},{47,20},{47,46},{47,47},{47,83},{47,124},{47,128},{47,132},{47,149},{47,159},{48,8},{48,13},{48,26},{48,48},{48,62},{48,149},{48,150},{48,174},{48,193},{48,195},{49,15},{49,21},{49,25},{49,49},{49,51},{49,145},{49,149},{49,151},{49,177},{49,188},{50,8},{50,49},{50,50},{50,54},{50,89},{50,105},{50,126},{50,152},{50,164},{50,165},{51,43},{51,51},{51,66},{51,68},{51,91},{51,131},{51,133},{51,153},{51,187},{51,189},{52,1},{52,39},{52,45},{52,52},{52,54},{52,110},{52,140},{52,150},{52,154},{52,163},{53,8},{53,53},{53,60},{53,64},{53,90},{53,138},{53,155},{53,157},{53,194},{53,204},{54,12},{54,28},{54,54},{54,60},{54,82},{54,112},{54,139},{54,151},{54,156},{54,183},{55,3},{55,17},{55,37},{55,55},{55,99},{55,112},{55,148},{55,157},{55,172},{55,189},{56,20},{56,31},{56,56},{56,80},{56,91},{56,152},{56,156},{56,158},{56,162},{56,180},{57,28},{57,57},{57,66},{57,81},{57,89},{57,134},{57,137},{57,159},{57,172},{57,196},{58,5},{58,58},{58,70},{58,78},{58,91},{58,118},{58,149},{58,154},{58,160},{58,201},{59,18},{59,24},{59,59},{59,88},{59,96},{59,150},{59,152},{59,161},{59,179},{59,183},{60,21},{60,38},{60,55},{60,59},{60,60},{60,162},{60,176},{60,187},{60,190},{60,197},{61,61},{61,69},{61,74},{61,93},{61,101},{61,111},{61,128},{61,163},{61,193},{61,196},{62,6},{62,7},{62,35},{62,62},{62,96},{62,103},{62,113},{62,129},{62,164},{62,200},{63,16},{63,27},{63,44},{63,63},{63,88},{63,121},{63,134},{63,165},{63,175},{63,188},{64,4},{64,26},{64,64},{64,79},{64,84},{64,119},{64,134},{64,136},{64,166},{64,168},{65,12},{65,13},{65,52},{65,57},{65,65},{65,106},{65,138},{65,142},{65,167},{65,176},{66,24},{66,30},{66,52},{66,66},{66,102},{66,112},{66,117},{66,122},{66,135},{66,168},{67,6},{67,57},{67,67},{67,85},{67,97},{67,140},{67,169},{67,182},{67,184},{67,186},{68,6},{68,58},{68,68},{68,71},{68,90},{68,134},{68,143},{68,145},{68,152},{68,170},{69,54},{69,57},{69,59},{69,69},{69,77},{69,103},{69,104},{69,114},{69,136},{69,171},{70,19},{70,24},{70,56},{70,70},{70,100},{70,105},{70,114},{70,128},{70,129},{70,172},{71,14},{71,52},{71,63},{71,70},{71,71},{71,120},{71,169},{71,173},{71,178},{71,196},{72,11},{72,25},{72,39},{72,66},{72,72},{72,120},{72,130},{72,132},{72,174},{72,199},{73,48},{73,49},{73,64},{73,73},{73,98},{73,111},{73,175},{73,179},{73,201},{73,202},{74,9},{74,15},{74,58},{74,74},{74,84},{74,107},{74,120},{74,135},{74,164},{74,176},{75,28},{75,41},{75,70},{75,75},{75,96},{75,133},{75,155},{75,166},{75,177},{75,202},{76,26},{76,45},{76,65},{76,76},{76,94},{76,144},{76,158},{76,172},{76,178},{76,203},{77,10},{77,13},{77,77},{77,84},{77,87},{77,127},{77,151},{77,163},{77,179},{77,191},{78,49},{78,55},{78,65},{78,78},{78,90},{78,122},{78,130},{78,139},{78,180},{78,182},{79,33},{79,43},{79,67},{79,79},{79,99},{79,123},{79,141},{79,181},{79,188},{79,202},{80,18},{80,19},{80,35},{80,46},{80,80},{80,153},{80,167},{80,182},{80,188},{80,193},{81,9},{81,16},{81,36},{81,55},{81,81},{81,143},{81,160},{81,183},{81,186},{81,191},{82,10},{82,11},{82,79},{82,82},{82,96},{82,108},{82,111},{82,126},{82,172},{82,184},{83,12},{83,36},{83,69},{83,83},{83,87},{83,148},{83,174},{83,185},{83,202},{83,204},{84,45},{84,47},{84,48},{84,75},{84,84},{84,108},{84,123},{84,142},{84,153},{84,186},{85,9},{85,46},{85,53},{85,54},{85,85},{85,115},{85,121},{85,129},{85,177},{85,187},{86,22},{86,64},{86,83},{86,86},{86,91},{86,107},{86,116},{86,171},{86,188},{86,199},{87,8},{87,22},{87,61},{87,81},{87,87},{87,104},{87,120},{87,182},{87,189},{87,198},{88,32},{88,33},{88,39},{88,51},{88,88},{88,129},{88,143},{88,171},{88,180},{88,190},{89,3},{89,21},{89,52},{89,89},{89,100},{89,103},{89,109},{89,115},{89,125},{89,191},{90,20},{90,40},{90,44},{90,61},{90,90},{90,118},{90,137},{90,153},{90,184},{90,192},{91,6},{91,23},{91,29},{91,84},{91,91},{91,144},{91,155},{91,173},{91,185},{91,193},{92,14},{92,49},{92,72},{92,92},{92,102},{92,147},{92,171},{92,185},{92,186},{92,194},{93,5},{93,21},{93,29},{93,65},{93,93},{93,105},{93,110},{93,119},{93,184},{93,195},{94,39},{94,80},{94,82},{94,94},{94,98},{94,107},{94,113},{94,131},{94,166},{94,196},{95,30},{95,47},{95,50},{95,63},{95,95},{95,104},{95,118},{95,161},{95,163},{95,197},{96,25},{96,34},{96,56},{96,68},{96,96},{96,116},{96,181},{96,186},{96,196},{96,198},{97,36},{97,38},{97,46},{97,89},{97,97},{97,113},{97,136},{97,150},{97,157},{97,199},{98,3},{98,12},{98,18},{98,30},{98,98},{98,136},{98,170},{98,187},{98,198},{98,200},{99,53},{99,62},{99,74},{99,97},{99,99},{99,104},{99,119},{99,156},{99,185},{99,201},{100,16},{100,68},{100,82},{100,95},{100,100},{100,106}};
 
                        for(looping=0;looping<10;looping++)
						{
							
                            SPADecoder(rows_p, LLR, h, LLR_ret, L_ch, L_dec, y, z, col);
							printf("%f\t", y[looping]);
						}
return 0;
	
}


Warning Messages
prog.c: In function 'main':
prog.c:169:78: warning: passing argument 7 of 'SPADecoder' from incompatible pointer type [-Wincompatible-pointer-types]
                             SPADecoder(rows_p, LLR, h, LLR_ret, L_ch, L_dec, y, z, col);
                                                                              ^
prog.c:59:6: note: expected 'int *' but argument is of type 'float *'
 void SPADecoder(int rows_p, double LLR[], int (*h)[2], double LLR_ret[], double L_ch[],  double L_dec[], int y[], int z, int col)


THANKS I HAVE CORRECTED MY ERROR.. DID MISTAKE IN DATA TYPE DECLARATION.
Was This Post Helpful? 0
  • +
  • -

#18 jimblumberg  Icon User is offline

  • member icon

Reputation: 5344
  • View blog
  • Posts: 16,676
  • Joined: 25-December 09

Re: Passing an array by reference in C?

Posted 31 August 2017 - 05:42 AM

Note that this function:
int codecheck(int col,int col_p,int rows_p,int (*h)[2],int x[])

Should really look more like:
int codecheck(int *h[COL_P],int x[])

Which means that you will need to fix the error messages that will occur by changing the variable names to the #defined constants.

And you didn't make the changes I suggested in my last post.


Jim
Was This Post Helpful? 0
  • +
  • -

#19 thaus_15  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 53
  • Joined: 09-May 17

Re: Passing an array by reference in C?

Posted 31 August 2017 - 05:42 AM

I have added one function to corrected code, it`s showing

warning messages
prog.c: In function 'main':
prog.c:236:2: error: variable-sized object may not be initialized
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
  ^
prog.c:236:14: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
              ^
prog.c:236:14: note: (near initialization for 'x')
prog.c:236:16: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                ^
prog.c:236:16: note: (near initialization for 'x')
prog.c:236:18: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                  ^
prog.c:236:18: note: (near initialization for 'x')
prog.c:236:20: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                    ^
prog.c:236:20: note: (near initialization for 'x')
prog.c:236:22: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                      ^
prog.c:236:22: note: (near initialization for 'x')
prog.c:236:24: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                        ^
prog.c:236:24: note: (near initialization for 'x')
prog.c:236:26: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                          ^
prog.c:236:26: note: (near initialization for 'x')
prog.c:236:28: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                            ^
prog.c:236:28: note: (near initialization for 'x')
prog.c:236:30: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                              ^
prog.c:236:30: note: (near initialization for 'x')
prog.c:236:32: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                                ^
prog.c:236:32: note: (near initialization for 'x')
prog.c:236:34: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                                  ^
prog.c:236:34: note: (near initialization for 'x')
prog.c:236:36: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                                    ^
prog.c:236:36: note: (near initialization for 'x')
prog.c:236:38: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                                      ^
prog.c:236:38: note: (near initialization for 'x')
prog.c:236:40: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                                        ^
prog.c:236:40: note: (near initialization for 'x')
prog.c:236:42: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                                          ^
prog.c:236:42: note: (near initialization for 'x')
prog.c:236:44: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                                            ^
prog.c:236:44: note: (near initialization for 'x')
prog.c:236:46: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                                              ^
prog.c:236:46: note: (near initialization for 'x')
prog.c:236:48: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                                                ^
prog.c:236:48: note: (near initialization for 'x')
prog.c:236:50: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                                                  ^
prog.c:236:50: note: (near initialization for 'x')
prog.c:236:52: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                                                    ^
prog.c:236:52: note: (near initialization for 'x')
prog.c:236:54: warning: excess elements in array initializer
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
                                                      ^
prog.c:236:54: note: (near initialization for 'x')
prog.c:237:5: error: expected ',' or ';' before 'int'
     int  ret,row=0;
     ^
prog.c:261:83: warning: passing argument 4 of 'InitializeChannelLLR' from incompatible pointer type [-Wincompatible-pointer-types]
                         InitializeChannelLLR( var, modulationScheme, noOfSymbols, x, noise,  L_ch, d, rows_p, h, LLR);
                                                                                   ^
prog.c:90:6: note: expected 'float *' but argument is of type 'int *'
 void InitializeChannelLLR (double var, int modulationScheme, int noOfSymbols, float x[], float noise[], double L_ch[], float d, int rows_p, int (*h)[2], double LLR[])
      ^
prog.c:292:6: error: expected expression before '}' token
      }
      


SOURCE CODE

#include <stdio.h>
#include <math.h>
 
#define COL 204
#define COL_P 2
#define ROWS_P 1020
 
int codecheck(int col,int col_p,int rows_p,int (*h)[2],int x[])
{	int i,j,m,f; //flags
	int sum = 0;
	int y[COL];
	
	for (i=0;i<COL;i++)
	y[i]=0;
	m=1;
	f=-1;
	for(i=0;i<rows_p;)							 
	{			
		for(j=0;j<rows_p;j++)
		{
			if(h[j][0]==m)
			{		
				y[m]=y[m] + x[h[j][1]-1];
					f++;
			}
		}
		y[m]=y[m]%2;
		m=m+1;
		i=f+1;
	}
 
	for (i = 0; i < COL; ++i) 
		{
			sum =sum+ y[i];
		}
	if (sum == 0) 
		{
			return 1;
		}
	else
		{	
			return -1;
		}
				
}
 
int codesum (int y[],int col)
{
    int sum=0;
    for(int i=0;i<COL;i++)
        sum+=y[i];
    //cout<< "sum="<< sum<<endl;
    if(sum>0)
        return 0;
    else
        return 1;
}



void ModulationSchemeValues (int modulationScheme, int noOfSymbols, double var, float d, int col, float rate, double snr)
{
	            switch (modulationScheme)
            {
                case 0:
                    //cout<<"case 0"<<endl;
                    var=1/(2*rate*snr);
                    noOfSymbols = col;
                    d=1;
                    break;
                case 1:
                    //cout<<"case 1"<<endl;
                    var=1/(4*rate*snr);
                    noOfSymbols = col/2;
                    d=1/sqrt(2);
                    break;
                case 2:
                    //cout<<"case 2"<<endl;
                    var=1/(8*rate*snr);
                    noOfSymbols = col/4;
                    d=1/sqrt(10);
                default:
                    var=1/(2*rate*snr);
                    noOfSymbols = col;
                    d=1;
                    break;
            }
}

void InitializeChannelLLR (double var, int modulationScheme, int noOfSymbols, float x[], float noise[], double L_ch[], float d, int rows_p, int (*h)[2], double LLR[])
{
    
    int j=0;   // temporary flags
   int k=0,t;
    for(int i=0;i<noOfSymbols;i++)							// using randnoise function introducing noise to all zero codeword
    {
        
            x[j]=d;
            noise[j]=(x[j])+0.8;
            L_ch[j]= 2*noise[j]/var;
            j++;
       
        
    }

    
    for(int j=0;j<rows_p;j++)
    {
        //cout<<"enter loop"<<endl;
        //cout<< "j="<<j<<endl;  //<<j<<"\t";
        t=h[j][1]-1;
        LLR[j]=L_ch[t];
    }
    //cout<<"L_ch initialize done \n";

}
 
 
void SPADecoder(int rows_p, double LLR[], int (*h)[2], double LLR_ret[], double L_ch[],  double L_dec[], int y[], int z, int col)
{
    double temp;
	int col_p;
    int i,j,k;
    for(i=0;i<rows_p;i++)
    {
        temp=1;
        for(j=0;j<rows_p;j++)
        {
            if(j!=i && h[j][0]==h[i][0])
            {
                temp=temp * tanhf(LLR[j]/2);
            }
        }
								
								
        LLR_ret[i] = log((1 + temp)/(1 - temp));     // lower and upper bounding the LLR
								
        if(LLR_ret[i] > 40)
        {
            LLR_ret[i]=40;
        }
        else if(LLR_ret[i]<-40)
        {
            LLR_ret[i]=-40;
        }
        
    }
    
    for(i=0;i<COL;i++)							// L_dec array used to decide the value of each bit of codeword here it is initalized to LLr value received from channel
    {
        L_dec[i]=L_ch[i];
    }
    
    
    for(i=1;i<col+1;i++)						// LLR values received by the variable nodes are added and stored in L_dec for decision making
    {
        for(j=0;j<rows_p;j++)
        {
            if(h[j][1]==i)
            {
                L_dec[i-1]=L_dec[i-1]+LLR_ret[j];
            }
            
        }
        
        if(L_dec[i-1]<=0)						// decision about the bit values of the received codeword is done her and stored in Y.
        {
            y[i-1]=1;
        }
        else
        {
            y[i-1]=0;
        }
        
    }
    
    
    //z = codesum(y,col);
    z=codecheck(col, col_p,rows_p,h,y); // checking whether the decoded codeword is all zero or not
    
    if(z==1)								// if decoded perfectly exit the deoding loop
    {
        return ;
    }
    // updating LLR values on variable nodes side for each variable and check node
    for(i=0;i<rows_p;i++)
    {
        temp=0;
        for(j=0;j<rows_p;j++)
        {
            if(j!=i && h[j][1]==h[i][1])
            {
                temp=temp + LLR_ret[j];
                k=h[i][1];
                
            }
        }
        LLR[i] = temp+L_ch[k-1];
    }
 
}
 
int main()
{
    
    
	// flags and counters
int z,i,j,N,k,ber_count,looping,t,sum;
    float d=1;
	float rate=0.5;
	int rows_p,col_p;
	int col,y[col],maxTransmissions=20,decoderIterations=10,maxErrors=100,errorsAccumulated=0;			// iterations gives the maximum number of time the decoder is run for each value of SNR
//	 printf("enter number of rows in the txt file being given as input\n");
//	 scanf("%d",&rows_p);
 
//	 printf("\n enter number of columns \n");
//	 scanf("%d",&col);
//	int *y=(int*) calloc (col,sizeof(int));	 //the decoded codeword will be saved here.
    
//	float *x=(float*) calloc (col,sizeof(float));
//	double *noise=(double*) calloc (col,sizeof(double));		// noise array is noise added to all zero codeword.
	//double noise[]={1.1,0.9,-0.1,1.1,-1.1,0.9}		;
    
	double var,snr;
	double temp; 								//temp variable
    
//	double *L_ch=(double*) calloc (col,sizeof(double));			//holds LLR values given by the channel
//	double *L_dec=(double*) calloc (col,sizeof(double));
    
    float noise[col];  // "x" will be used as a codeword and "y" is received codeword.
    double L_ch[col],L_dec[col];    //holds LLR values given by the channel
	double LLR[rows_p],LLR_ret[rows_p];					//hold updated LLR values at variable node and check node respectively
	double BER[11];												// BER array one for each SNR as SNR is varied from 0-10 in steps of 1
    float snr_db[]={0,1,2,3,4};
    int snr_range=5,snr_count;
	int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}
    int  ret,row=0;
	double error_bits,error;
    // Set Field Separator here

    int modulationScheme = 0,noOfSymbols;
    
int h[ROWS_P][COL_P]={{1,1},{1,18},{1,27},{1,82},{1,102},{1,103},{1,130},{1,177},{1,190},{1,203},{2,2},{2,15},{2,75},{2,80},{2,86},{2,104},{2,121},{2,141},{2,144},{2,191},{3,3},{3,31},{3,32},{3,42},{3,101},{3,105},{3,153},{3,159},{3,178},{3,199},{4,4},{4,37},{4,71},{4,75},{4,85},{4,106},{4,111},{4,114},{4,127},{4,164},{5,5},{5,17},{5,42},{5,72},{5,87},{5,107},{5,141},{5,158},{5,193},{5,197},{6,4},{6,6},{6,17},{6,78},{6,102},{6,108},{6,162},{6,165},{6,167},{6,174},{7,7},{7,23},{7,73},{7,80},{7,83},{7,109},{7,118},{7,168},{7,177},{7,178},{8,8},{8,33},{8,37},{8,73},{8,100},{8,110},{8,156},{8,173},{8,192},{8,197},{9,9},{9,40},{9,41},{9,88},{9,92},{9,103},{9,111},{9,173},{9,181},{9,199},{10,10},{10,14},{10,23},{10,53},{10,93},{10,107},{10,112},{10,137},{10,167},{10,175},{11,11},{11,19},{11,26},{11,28},{11,88},{11,110},{11,113},{11,116},{11,170},{11,191},{12,1},{12,12},{12,25},{12,86},{12,97},{12,108},{12,114},{12,124},{12,161},{12,192},{13,4},{13,13},{13,33},{13,34},{13,50},{13,115},{13,137},{13,140},{13,146},{13,160},{14,14},{14,31},{14,40},{14,58},{14,95},{14,116},{14,121},{14,166},{14,174},{14,203},{15,15},{15,68},{15,70},{15,87},{15,101},{15,109},{15,113},{15,117},{15,165},{15,180},{16,4},{16,16},{16,59},{16,67},{16,92},{16,118},{16,125},{16,131},{16,138},{16,151},{17,15},{17,17},{17,44},{17,71},{17,73},{17,119},{17,161},{17,190},{17,194},{17,198},{18,18},{18,47},{18,62},{18,85},{18,93},{18,120},{18,122},{18,125},{18,146},{18,181},{19,19},{19,22},{19,23},{19,37},{19,57},{19,121},{19,126},{19,130},{19,131},{19,143},{20,1},{20,20},{20,50},{20,51},{20,99},{20,106},{20,122},{20,169},{20,179},{20,200},{21,21},{21,32},{21,62},{21,72},{21,98},{21,123},{21,126},{21,154},{21,168},{21,204},{22,22},{22,31},{22,44},{22,89},{22,98},{22,124},{22,141},{22,160},{22,169},{22,176},{23,23},{23,32},{23,61},{23,65},{23,99},{23,125},{23,132},{23,133},{23,147},{23,152},{24,16},{24,24},{24,42},{24,73},{24,77},{24,126},{24,142},{24,145},{24,146},{24,147},{25,5},{25,24},{25,25},{25,55},{25,67},{25,127},{25,133},{25,165},{25,178},{25,185},{26,10},{26,26},{26,27},{26,40},{26,85},{26,128},{26,147},{26,155},{26,160},{26,200},{27,22},{27,27},{27,42},{27,50},{27,74},{27,108},{27,129},{27,154},{27,170},{27,195},{28,2},{28,28},{28,63},{28,67},{28,94},{28,130},{28,150},{28,171},{28,187},{28,192},{29,29},{29,48},{29,69},{29,79},{29,90},{29,116},{29,131},{29,159},{29,176},{29,200},{30,7},{30,30},{30,53},{30,58},{30,94},{30,127},{30,132},{30,140},{30,162},{30,189},{31,29},{31,31},{31,64},{31,77},{31,94},{31,117},{31,133},{31,167},{31,183},{31,190},{32,20},{32,30},{32,32},{32,74},{32,78},{32,115},{32,134},{32,151},{32,181},{32,194},{33,11},{33,33},{33,47},{33,76},{33,81},{33,109},{33,135},{33,154},{33,155},{33,179},{34,2},{34,7},{34,34},{34,71},{34,76},{34,136},{34,138},{34,159},{34,182},{34,183},{35,27},{35,29},{35,35},{35,60},{35,86},{35,123},{35,137},{35,149},{35,166},{35,189},{36,17},{36,35},{36,36},{36,48},{36,100},{36,138},{36,139},{36,146},{36,163},{36,168},{37,5},{37,34},{37,37},{37,38},{37,69},{37,117},{37,139},{37,145},{37,169},{37,203},{38,38},{38,56},{38,76},{38,92},{38,101},{38,106},{38,123},{38,140},{38,161},{38,170},{39,39},{39,41},{39,60},{39,76},{39,78},{39,125},{39,141},{39,142},{39,175},{39,198},{40,2},{40,35},{40,40},{40,43},{40,93},{40,114},{40,135},{40,142},{40,148},{40,158},{41,1},{41,2},{41,13},{41,41},{41,59},{41,109},{41,119},{41,132},{41,143},{41,157},{42,11},{42,42},{42,43},{42,92},{42,95},{42,115},{42,117},{42,144},{42,156},{42,204},{43,7},{43,9},{43,43},{43,45},{43,56},{43,122},{43,145},{43,192},{43,194},{43,201},{44,10},{44,44},{44,75},{44,83},{44,95},{44,110},{44,135},{44,146},{44,157},{44,180},{45,45},{45,63},{45,79},{45,81},{45,97},{45,127},{45,139},{45,147},{45,148},{45,195},{46,34},{46,46},{46,61},{46,66},{46,77},{46,105},{46,144},{46,148},{46,197},{46,201},{47,14},{47,20},{47,46},{47,47},{47,83},{47,124},{47,128},{47,132},{47,149},{47,159},{48,8},{48,13},{48,26},{48,48},{48,62},{48,149},{48,150},{48,174},{48,193},{48,195},{49,15},{49,21},{49,25},{49,49},{49,51},{49,145},{49,149},{49,151},{49,177},{49,188},{50,8},{50,49},{50,50},{50,54},{50,89},{50,105},{50,126},{50,152},{50,164},{50,165},{51,43},{51,51},{51,66},{51,68},{51,91},{51,131},{51,133},{51,153},{51,187},{51,189},{52,1},{52,39},{52,45},{52,52},{52,54},{52,110},{52,140},{52,150},{52,154},{52,163},{53,8},{53,53},{53,60},{53,64},{53,90},{53,138},{53,155},{53,157},{53,194},{53,204},{54,12},{54,28},{54,54},{54,60},{54,82},{54,112},{54,139},{54,151},{54,156},{54,183},{55,3},{55,17},{55,37},{55,55},{55,99},{55,112},{55,148},{55,157},{55,172},{55,189},{56,20},{56,31},{56,56},{56,80},{56,91},{56,152},{56,156},{56,158},{56,162},{56,180},{57,28},{57,57},{57,66},{57,81},{57,89},{57,134},{57,137},{57,159},{57,172},{57,196},{58,5},{58,58},{58,70},{58,78},{58,91},{58,118},{58,149},{58,154},{58,160},{58,201},{59,18},{59,24},{59,59},{59,88},{59,96},{59,150},{59,152},{59,161},{59,179},{59,183},{60,21},{60,38},{60,55},{60,59},{60,60},{60,162},{60,176},{60,187},{60,190},{60,197},{61,61},{61,69},{61,74},{61,93},{61,101},{61,111},{61,128},{61,163},{61,193},{61,196},{62,6},{62,7},{62,35},{62,62},{62,96},{62,103},{62,113},{62,129},{62,164},{62,200},{63,16},{63,27},{63,44},{63,63},{63,88},{63,121},{63,134},{63,165},{63,175},{63,188},{64,4},{64,26},{64,64},{64,79},{64,84},{64,119},{64,134},{64,136},{64,166},{64,168},{65,12},{65,13},{65,52},{65,57},{65,65},{65,106},{65,138},{65,142},{65,167},{65,176},{66,24},{66,30},{66,52},{66,66},{66,102},{66,112},{66,117},{66,122},{66,135},{66,168},{67,6},{67,57},{67,67},{67,85},{67,97},{67,140},{67,169},{67,182},{67,184},{67,186},{68,6},{68,58},{68,68},{68,71},{68,90},{68,134},{68,143},{68,145},{68,152},{68,170},{69,54},{69,57},{69,59},{69,69},{69,77},{69,103},{69,104},{69,114},{69,136},{69,171},{70,19},{70,24},{70,56},{70,70},{70,100},{70,105},{70,114},{70,128},{70,129},{70,172},{71,14},{71,52},{71,63},{71,70},{71,71},{71,120},{71,169},{71,173},{71,178},{71,196},{72,11},{72,25},{72,39},{72,66},{72,72},{72,120},{72,130},{72,132},{72,174},{72,199},{73,48},{73,49},{73,64},{73,73},{73,98},{73,111},{73,175},{73,179},{73,201},{73,202},{74,9},{74,15},{74,58},{74,74},{74,84},{74,107},{74,120},{74,135},{74,164},{74,176},{75,28},{75,41},{75,70},{75,75},{75,96},{75,133},{75,155},{75,166},{75,177},{75,202},{76,26},{76,45},{76,65},{76,76},{76,94},{76,144},{76,158},{76,172},{76,178},{76,203},{77,10},{77,13},{77,77},{77,84},{77,87},{77,127},{77,151},{77,163},{77,179},{77,191},{78,49},{78,55},{78,65},{78,78},{78,90},{78,122},{78,130},{78,139},{78,180},{78,182},{79,33},{79,43},{79,67},{79,79},{79,99},{79,123},{79,141},{79,181},{79,188},{79,202},{80,18},{80,19},{80,35},{80,46},{80,80},{80,153},{80,167},{80,182},{80,188},{80,193},{81,9},{81,16},{81,36},{81,55},{81,81},{81,143},{81,160},{81,183},{81,186},{81,191},{82,10},{82,11},{82,79},{82,82},{82,96},{82,108},{82,111},{82,126},{82,172},{82,184},{83,12},{83,36},{83,69},{83,83},{83,87},{83,148},{83,174},{83,185},{83,202},{83,204},{84,45},{84,47},{84,48},{84,75},{84,84},{84,108},{84,123},{84,142},{84,153},{84,186},{85,9},{85,46},{85,53},{85,54},{85,85},{85,115},{85,121},{85,129},{85,177},{85,187},{86,22},{86,64},{86,83},{86,86},{86,91},{86,107},{86,116},{86,171},{86,188},{86,199},{87,8},{87,22},{87,61},{87,81},{87,87},{87,104},{87,120},{87,182},{87,189},{87,198},{88,32},{88,33},{88,39},{88,51},{88,88},{88,129},{88,143},{88,171},{88,180},{88,190},{89,3},{89,21},{89,52},{89,89},{89,100},{89,103},{89,109},{89,115},{89,125},{89,191},{90,20},{90,40},{90,44},{90,61},{90,90},{90,118},{90,137},{90,153},{90,184},{90,192},{91,6},{91,23},{91,29},{91,84},{91,91},{91,144},{91,155},{91,173},{91,185},{91,193},{92,14},{92,49},{92,72},{92,92},{92,102},{92,147},{92,171},{92,185},{92,186},{92,194},{93,5},{93,21},{93,29},{93,65},{93,93},{93,105},{93,110},{93,119},{93,184},{93,195},{94,39},{94,80},{94,82},{94,94},{94,98},{94,107},{94,113},{94,131},{94,166},{94,196},{95,30},{95,47},{95,50},{95,63},{95,95},{95,104},{95,118},{95,161},{95,163},{95,197},{96,25},{96,34},{96,56},{96,68},{96,96},{96,116},{96,181},{96,186},{96,196},{96,198},{97,36},{97,38},{97,46},{97,89},{97,97},{97,113},{97,136},{97,150},{97,157},{97,199},{98,3},{98,12},{98,18},{98,30},{98,98},{98,136},{98,170},{98,187},{98,198},{98,200},{99,53},{99,62},{99,74},{99,97},{99,99},{99,104},{99,119},{99,156},{99,185},{99,201},{100,16},{100,68},{100,82},{100,95},{100,100},{100,106}};
 
                 for(snr_count=0;snr_count<snr_range;snr_count++)
	{
      //  cout<<"Decoder run for SNR in db=" <<snr_db[snr_count]<<endl;
				snr=pow(10,(snr_db[snr_count]/10));
				
				ModulationSchemeValues (modulationScheme, noOfSymbols, var, d, col, rate, snr);  // determining various values based on mdulation scheme
        
        							// calulating noise variance from SNR
				BER[snr_count]=0;									// initializing BER
             //   normal_distribution<double> dist(0.0, 1);
                N=0;
                errorsAccumulated=0;
					while(errorsAccumulated<=maxErrors && N<=maxTransmissions)
					{		
                        N++;
                        
                        InitializeChannelLLR( var, modulationScheme, noOfSymbols, x, noise,  L_ch, d, rows_p, h, LLR);
                        
                        for(looping=0;looping<decoderIterations;looping++)
						{
							
                            SPADecoder(rows_p, LLR, h, LLR_ret, L_ch, L_dec, y, z, col  );
                     printf("%d\t", y[looping]);
						}
										
							if(z==1)											// if decoded correctly BER for that codeword is zero
								{
									BER[snr_count]=BER[snr_count]+0;

								}
							else 												// if not decoded properly calulating the BER
								{		
									error_bits=0;
									for(i=0;i<col;i++)
									{
										if(y[i]!=0)
										{
											error_bits++;
											
										}
									}
                                    errorsAccumulated+=error_bits;
                                    error=error_bits/(double)col;
									BER[snr_count]=BER[snr_count]+error;
								}
                        if(N%300==0)
                     //   cout<<"iteration="<<N<<"\t"<<"errors accumulated="<<errorsAccumulated<<endl;
					}
					
					BER[snr_count]=BER[snr_count]/(double)N; 					// averaging BER over all decoding iterations.
					printf("snr=%lf\tBER[%d]=%lf \n",snr_db[snr_count],snr_count,BER[snr_count]);
	}
	
return 0;
		
	
}




Was This Post Helpful? 0
  • +
  • -

#20 jimblumberg  Icon User is offline

  • member icon

Reputation: 5344
  • View blog
  • Posts: 16,676
  • Joined: 25-December 09

Re: Passing an array by reference in C?

Posted 31 August 2017 - 07:59 AM

Quote

I have added one function to corrected code, it`s showing

Yes, I told you that you would have errors when you made those changes. You will need to change the "variables" listed in your error messages to the proper #defined constant. Example:

prog.c: In function 'main':
prog.c:236:2: error: variable-sized object may not be initialized
  int x[col]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}


Becomes:
    int x[COL]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1}; // Don't forget the semicolon.


Your function will also not need to pass those constants as parameters.

Jim
Was This Post Helpful? 0
  • +
  • -

#21 andrewsw  Icon User is offline

  • say what now
  • member icon

Reputation: 6408
  • View blog
  • Posts: 25,889
  • Joined: 12-December 12

Re: Passing an array by reference in C?

Posted 01 September 2017 - 12:21 AM

@OP Do not just post code and error messages with statements like "it's urgent" and "Please sort it out". You must demonstrate the efforts you are making to understand and resolve your issues. In particular, describe each time what you think the error(s) are telling you or, at least, what you think the problem might be.
Was This Post Helpful? 0
  • +
  • -

#22 thaus_15  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 53
  • Joined: 09-May 17

Re: Passing an array by reference in C?

Posted 01 September 2017 - 12:28 AM

Almost i have sort out the problems through study material. When i compiled my C codes, its showing Segmentation Fault (SIGSEGV). I gone through the TUTORIAL "Segmentation Violations/Faults". Then find that following causes of this problem.

Improper format control string in printf or scanf statements:

Forgetting to use "&" on the arguments to scanf:

Accessing beyond the bounds of an array:

Failure to initialize a pointer before accessing it:

Incorrect use of the "&" (address of) and "*" (dereferencing) operators:

I have checked the codes according to mentioned causes but eventhough i cant whats wrong in my code. Please point out location of an error. Thanks
#include <stdio.h>
#include <math.h>
 
#define COL 204
#define COL_P 2
#define ROWS_P 1020
 
int codecheck(int (*h)[2],int x[])
{	int i,j,m,f; //flags
	int sum = 0;
	int y[COL];
	
	for (i=0;i<COL;i++)
	y[i]=0;
	m=1;
	f=-1;
	for(i=0;i<ROWS_P;)							 
	{			
		for(j=0;j<ROWS_P;j++)
		{
			if(h[j][0]==m)
			{		
				y[m]=y[m] + x[h[j][1]-1];
					f++;
			}
		}
		y[m]=y[m]%2;
		m=m+1;
		i=f+1;
	}
 
	for (i = 0; i < COL; ++i) 
		{
			sum =sum+ y[i];
		}
	if (sum == 0) 
		{
			return 1;
		}
	else
		{	
			return -1;
		}
				
}
 
int codesum (int y[])
{
    int sum=0;
    for(int i=0;i<COL;i++)
        sum+=y[i];
    //cout<< "sum="<< sum<<endl;
    if(sum>0)
        return 0;
    else
        return 1;
}

void ModulationSchemeValues (int modulationScheme, int noOfSymbols, double var, float d, float rate, double snr)
{
	            switch (modulationScheme)
            {
                case 0:
                    //cout<<"case 0"<<endl;
                    var=1/(2*rate*snr);
                    noOfSymbols = COL;
                    d=1;
                    break;
                case 1:
                    //cout<<"case 1"<<endl;
                    var=1/(4*rate*snr);
                    noOfSymbols = COL/2;
                    d=1/sqrt(2);
                    break;
                case 2:
                    //cout<<"case 2"<<endl;
                    var=1/(8*rate*snr);
                    noOfSymbols = COL/4;
                    d=1/sqrt(10);
                default:
                    var=1/(2*rate*snr);
                    noOfSymbols = COL;
                    d=1;
                    break;
            }
}

void InitializeChannelLLR (double var, int modulationScheme, int noOfSymbols, int x[], float noise[], double L_ch[], float d, int (*h)[2], double LLR[])
{
    
    int j=0;   // temporary flags
   int k=0,t;
    for(int i=0;i<noOfSymbols;i++)							// using randnoise function introducing noise to all zero codeword
    {
        
            x[j]=d;
            noise[j]=(x[j])+0.8;
            L_ch[j]= 2*noise[j]/var;
            j++;
       
        
    }

    
    for(int j=0;j<ROWS_P;j++)
    {
        //cout<<"enter loop"<<endl;
        //cout<< "j="<<j<<endl;  //<<j<<"\t";
        t=h[j][1]-1;
        LLR[j]=L_ch[t];
    }
    //cout<<"L_ch initialize done \n";

}
 
void SPADecoder(double LLR[], int (*h)[2], double LLR_ret[], double L_ch[],  double L_dec[], int y[], int z)
{
    double temp;
	
    int i,j,k;
    for(i=0;i<ROWS_P;i++)
    {
        temp=1;
        for(j=0;j<ROWS_P;j++)
        {
            if(j!=i && h[j][0]==h[i][0])
            {
                temp=temp * tanhf(LLR[j]/2);
            }
        }
								
								
        LLR_ret[i] = log((1 + temp)/(1 - temp));     // lower and upper bounding the LLR
								
        if(LLR_ret[i] > 40)
        {
            LLR_ret[i]=40;
        }
        else if(LLR_ret[i]<-40)
        {
            LLR_ret[i]=-40;
        }
        
    }
    
    for(i=0;i<COL;i++)							// L_dec array used to decide the value of each bit of codeword here it is initalized to LLr value received from channel
    {
        L_dec[i]=L_ch[i];
    }
    
    
    for(i=1;i<COL+1;i++)						// LLR values received by the variable nodes are added and stored in L_dec for decision making
    {
        for(j=0;j<ROWS_P;j++)
        {
            if(h[j][1]==i)
            {
                L_dec[i-1]=L_dec[i-1]+LLR_ret[j];
            }
            
        }
        
        if(L_dec[i-1]<=0)						// decision about the bit values of the received codeword is done her and stored in Y.
        {
            y[i-1]=1;
        }
        else
        {
            y[i-1]=0;
        }
        
    }
    
    
    //z = codesum(y,col);
    z=codecheck(h,y); // checking whether the decoded codeword is all zero or not
    
    if(z==1)								// if decoded perfectly exit the deoding loop
    {
        return ;
    }
    // updating LLR values on variable nodes side for each variable and check node
    for(i=0;i<ROWS_P;i++)
    {
        temp=0;
        for(j=0;j<ROWS_P;j++)
        {
            if(j!=i && h[j][1]==h[i][1])
            {
                temp=temp + LLR_ret[j];
                k=h[i][1];
                
            }
        }
        LLR[i] = temp+L_ch[k-1];
    }
 
}
 
int main()
{
    
    
	// flags and counters
int z,i,j,N,k,ber_count,looping,t,sum;
    float d=1;
	float rate=0.5;
	
	int maxTransmissions=20,decoderIterations=10,maxErrors=100,errorsAccumulated=0;	
	int y[COL];	// iterations gives the maximum number of time the decoder is run for each value of SNR

    
	double var,snr;
	double temp; 								//temp variable

    
    float noise[COL];  
    double L_ch[COL],L_dec[COL];    
	double LLR[ROWS_P],LLR_ret[ROWS_P];					
	double BER[11];											
    float snr_db[]={0,1,2,3,4};
    int snr_range=5,snr_count;
	int x[]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1};
    int  ret,row=0;
	double error_bits,error;
    // Set Field Separator here

    int modulationScheme = 0,noOfSymbols=204;
    
int h[ROWS_P][COL_P]={{1,1},{1,18},{1,27},{1,82},{1,102},{1,103},{1,130},{1,177},{1,190},{1,203},{2,2},{2,15},{2,75},{2,80},{2,86},{2,104},{2,121},{2,141},{2,144},{2,191},{3,3},{3,31},{3,32},{3,42},{3,101},{3,105},{3,153},{3,159},{3,178},{3,199},{4,4},{4,37},{4,71},{4,75},{4,85},{4,106},{4,111},{4,114},{4,127},{4,164},{5,5},{5,17},{5,42},{5,72},{5,87},{5,107},{5,141},{5,158},{5,193},{5,197},{6,4},{6,6},{6,17},{6,78},{6,102},{6,108},{6,162},{6,165},{6,167},{6,174},{7,7},{7,23},{7,73},{7,80},{7,83},{7,109},{7,118},{7,168},{7,177},{7,178},{8,8},{8,33},{8,37},{8,73},{8,100},{8,110},{8,156},{8,173},{8,192},{8,197},{9,9},{9,40},{9,41},{9,88},{9,92},{9,103},{9,111},{9,173},{9,181},{9,199},{10,10},{10,14},{10,23},{10,53},{10,93},{10,107},{10,112},{10,137},{10,167},{10,175},{11,11},{11,19},{11,26},{11,28},{11,88},{11,110},{11,113},{11,116},{11,170},{11,191},{12,1},{12,12},{12,25},{12,86},{12,97},{12,108},{12,114},{12,124},{12,161},{12,192},{13,4},{13,13},{13,33},{13,34},{13,50},{13,115},{13,137},{13,140},{13,146},{13,160},{14,14},{14,31},{14,40},{14,58},{14,95},{14,116},{14,121},{14,166},{14,174},{14,203},{15,15},{15,68},{15,70},{15,87},{15,101},{15,109},{15,113},{15,117},{15,165},{15,180},{16,4},{16,16},{16,59},{16,67},{16,92},{16,118},{16,125},{16,131},{16,138},{16,151},{17,15},{17,17},{17,44},{17,71},{17,73},{17,119},{17,161},{17,190},{17,194},{17,198},{18,18},{18,47},{18,62},{18,85},{18,93},{18,120},{18,122},{18,125},{18,146},{18,181},{19,19},{19,22},{19,23},{19,37},{19,57},{19,121},{19,126},{19,130},{19,131},{19,143},{20,1},{20,20},{20,50},{20,51},{20,99},{20,106},{20,122},{20,169},{20,179},{20,200},{21,21},{21,32},{21,62},{21,72},{21,98},{21,123},{21,126},{21,154},{21,168},{21,204},{22,22},{22,31},{22,44},{22,89},{22,98},{22,124},{22,141},{22,160},{22,169},{22,176},{23,23},{23,32},{23,61},{23,65},{23,99},{23,125},{23,132},{23,133},{23,147},{23,152},{24,16},{24,24},{24,42},{24,73},{24,77},{24,126},{24,142},{24,145},{24,146},{24,147},{25,5},{25,24},{25,25},{25,55},{25,67},{25,127},{25,133},{25,165},{25,178},{25,185},{26,10},{26,26},{26,27},{26,40},{26,85},{26,128},{26,147},{26,155},{26,160},{26,200},{27,22},{27,27},{27,42},{27,50},{27,74},{27,108},{27,129},{27,154},{27,170},{27,195},{28,2},{28,28},{28,63},{28,67},{28,94},{28,130},{28,150},{28,171},{28,187},{28,192},{29,29},{29,48},{29,69},{29,79},{29,90},{29,116},{29,131},{29,159},{29,176},{29,200},{30,7},{30,30},{30,53},{30,58},{30,94},{30,127},{30,132},{30,140},{30,162},{30,189},{31,29},{31,31},{31,64},{31,77},{31,94},{31,117},{31,133},{31,167},{31,183},{31,190},{32,20},{32,30},{32,32},{32,74},{32,78},{32,115},{32,134},{32,151},{32,181},{32,194},{33,11},{33,33},{33,47},{33,76},{33,81},{33,109},{33,135},{33,154},{33,155},{33,179},{34,2},{34,7},{34,34},{34,71},{34,76},{34,136},{34,138},{34,159},{34,182},{34,183},{35,27},{35,29},{35,35},{35,60},{35,86},{35,123},{35,137},{35,149},{35,166},{35,189},{36,17},{36,35},{36,36},{36,48},{36,100},{36,138},{36,139},{36,146},{36,163},{36,168},{37,5},{37,34},{37,37},{37,38},{37,69},{37,117},{37,139},{37,145},{37,169},{37,203},{38,38},{38,56},{38,76},{38,92},{38,101},{38,106},{38,123},{38,140},{38,161},{38,170},{39,39},{39,41},{39,60},{39,76},{39,78},{39,125},{39,141},{39,142},{39,175},{39,198},{40,2},{40,35},{40,40},{40,43},{40,93},{40,114},{40,135},{40,142},{40,148},{40,158},{41,1},{41,2},{41,13},{41,41},{41,59},{41,109},{41,119},{41,132},{41,143},{41,157},{42,11},{42,42},{42,43},{42,92},{42,95},{42,115},{42,117},{42,144},{42,156},{42,204},{43,7},{43,9},{43,43},{43,45},{43,56},{43,122},{43,145},{43,192},{43,194},{43,201},{44,10},{44,44},{44,75},{44,83},{44,95},{44,110},{44,135},{44,146},{44,157},{44,180},{45,45},{45,63},{45,79},{45,81},{45,97},{45,127},{45,139},{45,147},{45,148},{45,195},{46,34},{46,46},{46,61},{46,66},{46,77},{46,105},{46,144},{46,148},{46,197},{46,201},{47,14},{47,20},{47,46},{47,47},{47,83},{47,124},{47,128},{47,132},{47,149},{47,159},{48,8},{48,13},{48,26},{48,48},{48,62},{48,149},{48,150},{48,174},{48,193},{48,195},{49,15},{49,21},{49,25},{49,49},{49,51},{49,145},{49,149},{49,151},{49,177},{49,188},{50,8},{50,49},{50,50},{50,54},{50,89},{50,105},{50,126},{50,152},{50,164},{50,165},{51,43},{51,51},{51,66},{51,68},{51,91},{51,131},{51,133},{51,153},{51,187},{51,189},{52,1},{52,39},{52,45},{52,52},{52,54},{52,110},{52,140},{52,150},{52,154},{52,163},{53,8},{53,53},{53,60},{53,64},{53,90},{53,138},{53,155},{53,157},{53,194},{53,204},{54,12},{54,28},{54,54},{54,60},{54,82},{54,112},{54,139},{54,151},{54,156},{54,183},{55,3},{55,17},{55,37},{55,55},{55,99},{55,112},{55,148},{55,157},{55,172},{55,189},{56,20},{56,31},{56,56},{56,80},{56,91},{56,152},{56,156},{56,158},{56,162},{56,180},{57,28},{57,57},{57,66},{57,81},{57,89},{57,134},{57,137},{57,159},{57,172},{57,196},{58,5},{58,58},{58,70},{58,78},{58,91},{58,118},{58,149},{58,154},{58,160},{58,201},{59,18},{59,24},{59,59},{59,88},{59,96},{59,150},{59,152},{59,161},{59,179},{59,183},{60,21},{60,38},{60,55},{60,59},{60,60},{60,162},{60,176},{60,187},{60,190},{60,197},{61,61},{61,69},{61,74},{61,93},{61,101},{61,111},{61,128},{61,163},{61,193},{61,196},{62,6},{62,7},{62,35},{62,62},{62,96},{62,103},{62,113},{62,129},{62,164},{62,200},{63,16},{63,27},{63,44},{63,63},{63,88},{63,121},{63,134},{63,165},{63,175},{63,188},{64,4},{64,26},{64,64},{64,79},{64,84},{64,119},{64,134},{64,136},{64,166},{64,168},{65,12},{65,13},{65,52},{65,57},{65,65},{65,106},{65,138},{65,142},{65,167},{65,176},{66,24},{66,30},{66,52},{66,66},{66,102},{66,112},{66,117},{66,122},{66,135},{66,168},{67,6},{67,57},{67,67},{67,85},{67,97},{67,140},{67,169},{67,182},{67,184},{67,186},{68,6},{68,58},{68,68},{68,71},{68,90},{68,134},{68,143},{68,145},{68,152},{68,170},{69,54},{69,57},{69,59},{69,69},{69,77},{69,103},{69,104},{69,114},{69,136},{69,171},{70,19},{70,24},{70,56},{70,70},{70,100},{70,105},{70,114},{70,128},{70,129},{70,172},{71,14},{71,52},{71,63},{71,70},{71,71},{71,120},{71,169},{71,173},{71,178},{71,196},{72,11},{72,25},{72,39},{72,66},{72,72},{72,120},{72,130},{72,132},{72,174},{72,199},{73,48},{73,49},{73,64},{73,73},{73,98},{73,111},{73,175},{73,179},{73,201},{73,202},{74,9},{74,15},{74,58},{74,74},{74,84},{74,107},{74,120},{74,135},{74,164},{74,176},{75,28},{75,41},{75,70},{75,75},{75,96},{75,133},{75,155},{75,166},{75,177},{75,202},{76,26},{76,45},{76,65},{76,76},{76,94},{76,144},{76,158},{76,172},{76,178},{76,203},{77,10},{77,13},{77,77},{77,84},{77,87},{77,127},{77,151},{77,163},{77,179},{77,191},{78,49},{78,55},{78,65},{78,78},{78,90},{78,122},{78,130},{78,139},{78,180},{78,182},{79,33},{79,43},{79,67},{79,79},{79,99},{79,123},{79,141},{79,181},{79,188},{79,202},{80,18},{80,19},{80,35},{80,46},{80,80},{80,153},{80,167},{80,182},{80,188},{80,193},{81,9},{81,16},{81,36},{81,55},{81,81},{81,143},{81,160},{81,183},{81,186},{81,191},{82,10},{82,11},{82,79},{82,82},{82,96},{82,108},{82,111},{82,126},{82,172},{82,184},{83,12},{83,36},{83,69},{83,83},{83,87},{83,148},{83,174},{83,185},{83,202},{83,204},{84,45},{84,47},{84,48},{84,75},{84,84},{84,108},{84,123},{84,142},{84,153},{84,186},{85,9},{85,46},{85,53},{85,54},{85,85},{85,115},{85,121},{85,129},{85,177},{85,187},{86,22},{86,64},{86,83},{86,86},{86,91},{86,107},{86,116},{86,171},{86,188},{86,199},{87,8},{87,22},{87,61},{87,81},{87,87},{87,104},{87,120},{87,182},{87,189},{87,198},{88,32},{88,33},{88,39},{88,51},{88,88},{88,129},{88,143},{88,171},{88,180},{88,190},{89,3},{89,21},{89,52},{89,89},{89,100},{89,103},{89,109},{89,115},{89,125},{89,191},{90,20},{90,40},{90,44},{90,61},{90,90},{90,118},{90,137},{90,153},{90,184},{90,192},{91,6},{91,23},{91,29},{91,84},{91,91},{91,144},{91,155},{91,173},{91,185},{91,193},{92,14},{92,49},{92,72},{92,92},{92,102},{92,147},{92,171},{92,185},{92,186},{92,194},{93,5},{93,21},{93,29},{93,65},{93,93},{93,105},{93,110},{93,119},{93,184},{93,195},{94,39},{94,80},{94,82},{94,94},{94,98},{94,107},{94,113},{94,131},{94,166},{94,196},{95,30},{95,47},{95,50},{95,63},{95,95},{95,104},{95,118},{95,161},{95,163},{95,197},{96,25},{96,34},{96,56},{96,68},{96,96},{96,116},{96,181},{96,186},{96,196},{96,198},{97,36},{97,38},{97,46},{97,89},{97,97},{97,113},{97,136},{97,150},{97,157},{97,199},{98,3},{98,12},{98,18},{98,30},{98,98},{98,136},{98,170},{98,187},{98,198},{98,200},{99,53},{99,62},{99,74},{99,97},{99,99},{99,104},{99,119},{99,156},{99,185},{99,201},{100,16},{100,68},{100,82},{100,95},{100,100},{100,106}};
 
                 for(snr_count=0;snr_count<snr_range;snr_count++)
	{
      //  cout<<"Decoder run for SNR in db=" <<snr_db[snr_count]<<endl;
				snr=pow(10,(snr_db[snr_count]/10));
				
				ModulationSchemeValues (modulationScheme, noOfSymbols, var, d, rate, snr);  // determining various values based on mdulation scheme
        
        							// calulating noise variance from SNR
				BER[snr_count]=0;									// initializing BER
             //   normal_distribution<double> dist(0.0, 1);
                N=0;
                errorsAccumulated=0;
					while(errorsAccumulated<=maxErrors && N<=maxTransmissions)
					{		
                        N++;
                        
                        InitializeChannelLLR( var, modulationScheme, noOfSymbols, x, noise,  L_ch, d, h, LLR);
                        
                        for(looping=0;looping<decoderIterations;looping++)
						{
							
                            SPADecoder(LLR, h, LLR_ret, L_ch, L_dec, y, z);
                     printf("%d\t", y[looping]);
						}
										
							if(z==1)											// if decoded correctly BER for that codeword is zero
								{
									BER[snr_count]=BER[snr_count]+0;

								}
							else 												// if not decoded properly calulating the BER
								{		
									error_bits=0;
									for(i=0;i<COL;i++)
									{
										if(y[i]!=0)
										{
											error_bits++;
											
										}
									}
                                    errorsAccumulated+=error_bits;
                                    error=error_bits/(double)COL;
									BER[snr_count]=BER[snr_count]+error;
								}
                   if(N%300==0)
                printf("iteration=%d \t errors accumulated=%d \n",N,errorsAccumulated);
					}
					
				BER[snr_count]=BER[snr_count]/(double)N; 					// averaging BER over all decoding iterations.
					printf("snr=%lf\tBER[%d]=%lf \n",snr_db[snr_count],snr_count,BER[snr_count]);
				
	}
		return 0;
}



Was This Post Helpful? 0
  • +
  • -

#23 Thomas1965  Icon User is offline

  • D.I.C Regular

Reputation: 66
  • View blog
  • Posts: 283
  • Joined: 09-September 16

Re: Passing an array by reference in C?

Posted 01 September 2017 - 04:22 AM

As far as I see it the problem is in for(i=0; i<ROWS_P;) in the function codecheck.
Seems i never gets over 996 so this is an endless loop. Unfortunately I have no idea to solve the problem. I added some logging to your code, maybe it helps other people.
#include <stdio.h>
#include <math.h>

#define COL 204
#define COL_P 2
#define ROWS_P 1020

#define TRACE(...)  printf(__VA_ARGS__)

int codecheck(int (*h)[2],int x[])
{
  TRACE("\n** Entering %s", __FUNCTION__);
  int i,j,m,f; //flags
  int sum = 0;
  int y[COL];

  for (i=0; i<COL; i++)
    y[i]=0;

  m=1;
  f=-1;
  for(i=0; i<ROWS_P;)
  {
    for(j=0; j<ROWS_P; j++)
    {
      if(h[j][0]== m)
      {
        y[m]=y[m] + x[h[j][1]-1];
        f++;
      }
    }
    y[m]= y[m] % 2;
    m=m+1;
    i=f+1;
    TRACE("\n** %s(%u) i = %d", __FUNCTION__, __LINE__, i);
  }

  for (i = 0; i < COL; ++i)
  {
    sum =sum+ y[i];
  }
  TRACE("\n** Leaving %s", __FUNCTION__);
  if (sum == 0)
  {
    return 1;
  }
  else
  {
    return -1;
  }

}

int codesum (int y[])
{
  TRACE("\n** Entering %s", __FUNCTION__);
  int sum=0;
  for(int i=0; i<COL; i++)
    sum+=y[i];
  //cout<< "sum="<< sum<<endl;
  TRACE("\n** Leaving %s", __FUNCTION__);
  if(sum>0)
    return 0;
  else
    return 1;
}

void ModulationSchemeValues (int modulationScheme, int noOfSymbols, double var, float d, float rate, double snr)
{
  TRACE("\n** Entering %s", __FUNCTION__);
  switch (modulationScheme)
  {
  case 0:
    //cout<<"case 0"<<endl;
    var=1/(2*rate*snr);
    noOfSymbols = COL;
    d=1;
    break;
  case 1:
    //cout<<"case 1"<<endl;
    var=1/(4*rate*snr);
    noOfSymbols = COL/2;
    d=1/sqrt(2);
    break;
  case 2:
    //cout<<"case 2"<<endl;
    var=1/(8*rate*snr);
    noOfSymbols = COL/4;
    d=1/sqrt(10);
  default:
    var=1/(2*rate*snr);
    noOfSymbols = COL;
    d=1;
    break;
  }
  TRACE("\n** Leaving %s", __FUNCTION__);
}

void InitializeChannelLLR (double var, int modulationScheme, int noOfSymbols, int x[], float noise[], double L_ch[], float d, int (*h)[2], double LLR[])
{
  TRACE("\n** Entering %s", __FUNCTION__);
  int j=0;   // temporary flags
  int k=0,t;
  for(int i=0; i<noOfSymbols; i++)							// using randnoise function introducing noise to all zero codeword
  {

    x[j]=d;
    noise[j]=(x[j])+0.8;
    L_ch[j]= 2*noise[j]/var;
    j++;


  }


  for(int j=0; j<ROWS_P; j++)
  {
    //cout<<"enter loop"<<endl;
    //cout<< "j="<<j<<endl;  //<<j<<"\t";
    t=h[j][1]-1;
    LLR[j]=L_ch[t];
  }
  //cout<<"L_ch initialize done \n";
  TRACE("\n** Leaving %s", __FUNCTION__);
}

void SPADecoder(double LLR[], int (*h)[2], double LLR_ret[], double L_ch[],  double L_dec[], int y[], int z)
{
  TRACE("\n** Entering %s", __FUNCTION__);

  double temp;

  int i,j,k;
  for(i=0; i<ROWS_P; i++)
  {
    temp=1;
    for(j=0; j<ROWS_P; j++)
    {
      if(j!=i && h[j][0]==h[i][0])
      {
        temp=temp * tanhf(LLR[j]/2);
      }
    }


    LLR_ret[i] = log((1 + temp)/(1 - temp));     // lower and upper bounding the LLR

    if(LLR_ret[i] > 40)
    {
      LLR_ret[i]=40;
    }
    else if(LLR_ret[i]<-40)
    {
      LLR_ret[i]=-40;
    }

  }

  for(i=0; i<COL; i++)							// L_dec array used to decide the value of each bit of codeword here it is initalized to LLr value received from channel
  {
    L_dec[i]=L_ch[i];
  }


  for(i=1; i<COL+1; i++)						// LLR values received by the variable nodes are added and stored in L_dec for decision making
  {
    for(j=0; j<ROWS_P; j++)
    {
      if(h[j][1]==i)
      {
        L_dec[i-1]=L_dec[i-1]+LLR_ret[j];
      }

    }

    if(L_dec[i-1]<=0)						// decision about the bit values of the received codeword is done her and stored in Y.
    {
      y[i-1]=1;
    }
    else
    {
      y[i-1]=0;
    }

  }


  //z = codesum(y,col);
  z=codecheck(h,y); // checking whether the decoded codeword is all zero or not

  if(z==1)								// if decoded perfectly exit the deoding loop
  {
    return ;
  }
  // updating LLR values on variable nodes side for each variable and check node
  for(i=0; i<ROWS_P; i++)
  {
    temp=0;
    for(j=0; j<ROWS_P; j++)
    {
      if(j!=i && h[j][1]==h[i][1])
      {
        temp=temp + LLR_ret[j];
        k=h[i][1];

      }
    }
    LLR[i] = temp+L_ch[k-1];
  }
  TRACE("\n** Leaving %s", __FUNCTION__);
}

int main()
{
  TRACE("\n** Entering %s", __FUNCTION__);

  // flags and counters
  int z,i,j,N,k,ber_count,looping,t,sum;
  float d=1;
  float rate=0.5;

  int maxTransmissions=20,decoderIterations=10,maxErrors=100,errorsAccumulated=0;
  int y[COL];	// iterations gives the maximum number of time the decoder is run for each value of SNR


  double var,snr;
  double temp; 								//temp variable


  float noise[COL];
  double L_ch[COL],L_dec[COL];
  double LLR[ROWS_P],LLR_ret[ROWS_P];
  double BER[11];
  float snr_db[]= {0,1,2,3,4};
  int snr_range=5,snr_count;
  int x[]= {0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1};
  int  ret,row=0;
  double error_bits,error;
  // Set Field Separator here

  int modulationScheme = 0,noOfSymbols=204;

  int h[ROWS_P][COL_P]= {{1,1},{1,18},{1,27},{1,82},{1,102},{1,103},{1,130},{1,177},{1,190},{1,203},{2,2},{2,15},{2,75},{2,80},{2,86},{2,104},{2,121},{2,141},{2,144},{2,191},{3,3},{3,31},{3,32},{3,42},{3,101},{3,105},{3,153},{3,159},{3,178},{3,199},{4,4},{4,37},{4,71},{4,75},{4,85},{4,106},{4,111},{4,114},{4,127},{4,164},{5,5},{5,17},{5,42},{5,72},{5,87},{5,107},{5,141},{5,158},{5,193},{5,197},{6,4},{6,6},{6,17},{6,78},{6,102},{6,108},{6,162},{6,165},{6,167},{6,174},{7,7},{7,23},{7,73},{7,80},{7,83},{7,109},{7,118},{7,168},{7,177},{7,178},{8,8},{8,33},{8,37},{8,73},{8,100},{8,110},{8,156},{8,173},{8,192},{8,197},{9,9},{9,40},{9,41},{9,88},{9,92},{9,103},{9,111},{9,173},{9,181},{9,199},{10,10},{10,14},{10,23},{10,53},{10,93},{10,107},{10,112},{10,137},{10,167},{10,175},{11,11},{11,19},{11,26},{11,28},{11,88},{11,110},{11,113},{11,116},{11,170},{11,191},{12,1},{12,12},{12,25},{12,86},{12,97},{12,108},{12,114},{12,124},{12,161},{12,192},{13,4},{13,13},{13,33},{13,34},{13,50},{13,115},{13,137},{13,140},{13,146},{13,160},{14,14},{14,31},{14,40},{14,58},{14,95},{14,116},{14,121},{14,166},{14,174},{14,203},{15,15},{15,68},{15,70},{15,87},{15,101},{15,109},{15,113},{15,117},{15,165},{15,180},{16,4},{16,16},{16,59},{16,67},{16,92},{16,118},{16,125},{16,131},{16,138},{16,151},{17,15},{17,17},{17,44},{17,71},{17,73},{17,119},{17,161},{17,190},{17,194},{17,198},{18,18},{18,47},{18,62},{18,85},{18,93},{18,120},{18,122},{18,125},{18,146},{18,181},{19,19},{19,22},{19,23},{19,37},{19,57},{19,121},{19,126},{19,130},{19,131},{19,143},{20,1},{20,20},{20,50},{20,51},{20,99},{20,106},{20,122},{20,169},{20,179},{20,200},{21,21},{21,32},{21,62},{21,72},{21,98},{21,123},{21,126},{21,154},{21,168},{21,204},{22,22},{22,31},{22,44},{22,89},{22,98},{22,124},{22,141},{22,160},{22,169},{22,176},{23,23},{23,32},{23,61},{23,65},{23,99},{23,125},{23,132},{23,133},{23,147},{23,152},{24,16},{24,24},{24,42},{24,73},{24,77},{24,126},{24,142},{24,145},{24,146},{24,147},{25,5},{25,24},{25,25},{25,55},{25,67},{25,127},{25,133},{25,165},{25,178},{25,185},{26,10},{26,26},{26,27},{26,40},{26,85},{26,128},{26,147},{26,155},{26,160},{26,200},{27,22},{27,27},{27,42},{27,50},{27,74},{27,108},{27,129},{27,154},{27,170},{27,195},{28,2},{28,28},{28,63},{28,67},{28,94},{28,130},{28,150},{28,171},{28,187},{28,192},{29,29},{29,48},{29,69},{29,79},{29,90},{29,116},{29,131},{29,159},{29,176},{29,200},{30,7},{30,30},{30,53},{30,58},{30,94},{30,127},{30,132},{30,140},{30,162},{30,189},{31,29},{31,31},{31,64},{31,77},{31,94},{31,117},{31,133},{31,167},{31,183},{31,190},{32,20},{32,30},{32,32},{32,74},{32,78},{32,115},{32,134},{32,151},{32,181},{32,194},{33,11},{33,33},{33,47},{33,76},{33,81},{33,109},{33,135},{33,154},{33,155},{33,179},{34,2},{34,7},{34,34},{34,71},{34,76},{34,136},{34,138},{34,159},{34,182},{34,183},{35,27},{35,29},{35,35},{35,60},{35,86},{35,123},{35,137},{35,149},{35,166},{35,189},{36,17},{36,35},{36,36},{36,48},{36,100},{36,138},{36,139},{36,146},{36,163},{36,168},{37,5},{37,34},{37,37},{37,38},{37,69},{37,117},{37,139},{37,145},{37,169},{37,203},{38,38},{38,56},{38,76},{38,92},{38,101},{38,106},{38,123},{38,140},{38,161},{38,170},{39,39},{39,41},{39,60},{39,76},{39,78},{39,125},{39,141},{39,142},{39,175},{39,198},{40,2},{40,35},{40,40},{40,43},{40,93},{40,114},{40,135},{40,142},{40,148},{40,158},{41,1},{41,2},{41,13},{41,41},{41,59},{41,109},{41,119},{41,132},{41,143},{41,157},{42,11},{42,42},{42,43},{42,92},{42,95},{42,115},{42,117},{42,144},{42,156},{42,204},{43,7},{43,9},{43,43},{43,45},{43,56},{43,122},{43,145},{43,192},{43,194},{43,201},{44,10},{44,44},{44,75},{44,83},{44,95},{44,110},{44,135},{44,146},{44,157},{44,180},{45,45},{45,63},{45,79},{45,81},{45,97},{45,127},{45,139},{45,147},{45,148},{45,195},{46,34},{46,46},{46,61},{46,66},{46,77},{46,105},{46,144},{46,148},{46,197},{46,201},{47,14},{47,20},{47,46},{47,47},{47,83},{47,124},{47,128},{47,132},{47,149},{47,159},{48,8},{48,13},{48,26},{48,48},{48,62},{48,149},{48,150},{48,174},{48,193},{48,195},{49,15},{49,21},{49,25},{49,49},{49,51},{49,145},{49,149},{49,151},{49,177},{49,188},{50,8},{50,49},{50,50},{50,54},{50,89},{50,105},{50,126},{50,152},{50,164},{50,165},{51,43},{51,51},{51,66},{51,68},{51,91},{51,131},{51,133},{51,153},{51,187},{51,189},{52,1},{52,39},{52,45},{52,52},{52,54},{52,110},{52,140},{52,150},{52,154},{52,163},{53,8},{53,53},{53,60},{53,64},{53,90},{53,138},{53,155},{53,157},{53,194},{53,204},{54,12},{54,28},{54,54},{54,60},{54,82},{54,112},{54,139},{54,151},{54,156},{54,183},{55,3},{55,17},{55,37},{55,55},{55,99},{55,112},{55,148},{55,157},{55,172},{55,189},{56,20},{56,31},{56,56},{56,80},{56,91},{56,152},{56,156},{56,158},{56,162},{56,180},{57,28},{57,57},{57,66},{57,81},{57,89},{57,134},{57,137},{57,159},{57,172},{57,196},{58,5},{58,58},{58,70},{58,78},{58,91},{58,118},{58,149},{58,154},{58,160},{58,201},{59,18},{59,24},{59,59},{59,88},{59,96},{59,150},{59,152},{59,161},{59,179},{59,183},{60,21},{60,38},{60,55},{60,59},{60,60},{60,162},{60,176},{60,187},{60,190},{60,197},{61,61},{61,69},{61,74},{61,93},{61,101},{61,111},{61,128},{61,163},{61,193},{61,196},{62,6},{62,7},{62,35},{62,62},{62,96},{62,103},{62,113},{62,129},{62,164},{62,200},{63,16},{63,27},{63,44},{63,63},{63,88},{63,121},{63,134},{63,165},{63,175},{63,188},{64,4},{64,26},{64,64},{64,79},{64,84},{64,119},{64,134},{64,136},{64,166},{64,168},{65,12},{65,13},{65,52},{65,57},{65,65},{65,106},{65,138},{65,142},{65,167},{65,176},{66,24},{66,30},{66,52},{66,66},{66,102},{66,112},{66,117},{66,122},{66,135},{66,168},{67,6},{67,57},{67,67},{67,85},{67,97},{67,140},{67,169},{67,182},{67,184},{67,186},{68,6},{68,58},{68,68},{68,71},{68,90},{68,134},{68,143},{68,145},{68,152},{68,170},{69,54},{69,57},{69,59},{69,69},{69,77},{69,103},{69,104},{69,114},{69,136},{69,171},{70,19},{70,24},{70,56},{70,70},{70,100},{70,105},{70,114},{70,128},{70,129},{70,172},{71,14},{71,52},{71,63},{71,70},{71,71},{71,120},{71,169},{71,173},{71,178},{71,196},{72,11},{72,25},{72,39},{72,66},{72,72},{72,120},{72,130},{72,132},{72,174},{72,199},{73,48},{73,49},{73,64},{73,73},{73,98},{73,111},{73,175},{73,179},{73,201},{73,202},{74,9},{74,15},{74,58},{74,74},{74,84},{74,107},{74,120},{74,135},{74,164},{74,176},{75,28},{75,41},{75,70},{75,75},{75,96},{75,133},{75,155},{75,166},{75,177},{75,202},{76,26},{76,45},{76,65},{76,76},{76,94},{76,144},{76,158},{76,172},{76,178},{76,203},{77,10},{77,13},{77,77},{77,84},{77,87},{77,127},{77,151},{77,163},{77,179},{77,191},{78,49},{78,55},{78,65},{78,78},{78,90},{78,122},{78,130},{78,139},{78,180},{78,182},{79,33},{79,43},{79,67},{79,79},{79,99},{79,123},{79,141},{79,181},{79,188},{79,202},{80,18},{80,19},{80,35},{80,46},{80,80},{80,153},{80,167},{80,182},{80,188},{80,193},{81,9},{81,16},{81,36},{81,55},{81,81},{81,143},{81,160},{81,183},{81,186},{81,191},{82,10},{82,11},{82,79},{82,82},{82,96},{82,108},{82,111},{82,126},{82,172},{82,184},{83,12},{83,36},{83,69},{83,83},{83,87},{83,148},{83,174},{83,185},{83,202},{83,204},{84,45},{84,47},{84,48},{84,75},{84,84},{84,108},{84,123},{84,142},{84,153},{84,186},{85,9},{85,46},{85,53},{85,54},{85,85},{85,115},{85,121},{85,129},{85,177},{85,187},{86,22},{86,64},{86,83},{86,86},{86,91},{86,107},{86,116},{86,171},{86,188},{86,199},{87,8},{87,22},{87,61},{87,81},{87,87},{87,104},{87,120},{87,182},{87,189},{87,198},{88,32},{88,33},{88,39},{88,51},{88,88},{88,129},{88,143},{88,171},{88,180},{88,190},{89,3},{89,21},{89,52},{89,89},{89,100},{89,103},{89,109},{89,115},{89,125},{89,191},{90,20},{90,40},{90,44},{90,61},{90,90},{90,118},{90,137},{90,153},{90,184},{90,192},{91,6},{91,23},{91,29},{91,84},{91,91},{91,144},{91,155},{91,173},{91,185},{91,193},{92,14},{92,49},{92,72},{92,92},{92,102},{92,147},{92,171},{92,185},{92,186},{92,194},{93,5},{93,21},{93,29},{93,65},{93,93},{93,105},{93,110},{93,119},{93,184},{93,195},{94,39},{94,80},{94,82},{94,94},{94,98},{94,107},{94,113},{94,131},{94,166},{94,196},{95,30},{95,47},{95,50},{95,63},{95,95},{95,104},{95,118},{95,161},{95,163},{95,197},{96,25},{96,34},{96,56},{96,68},{96,96},{96,116},{96,181},{96,186},{96,196},{96,198},{97,36},{97,38},{97,46},{97,89},{97,97},{97,113},{97,136},{97,150},{97,157},{97,199},{98,3},{98,12},{98,18},{98,30},{98,98},{98,136},{98,170},{98,187},{98,198},{98,200},{99,53},{99,62},{99,74},{99,97},{99,99},{99,104},{99,119},{99,156},{99,185},{99,201},{100,16},{100,68},{100,82},{100,95},{100,100},{100,106}};

  for(snr_count=0; snr_count<snr_range; snr_count++)
  {
    //  cout<<"Decoder run for SNR in db=" <<snr_db[snr_count]<<endl;
    snr=pow(10,(snr_db[snr_count]/10));

    ModulationSchemeValues (modulationScheme, noOfSymbols, var, d, rate, snr);  // determining various values based on mdulation scheme

    // calulating noise variance from SNR
    BER[snr_count]=0;									// initializing BER
    //   normal_distribution<double> dist(0.0, 1);
    N=0;
    errorsAccumulated=0;
    while(errorsAccumulated<=maxErrors && N<=maxTransmissions)
    {
      N++;

      InitializeChannelLLR( var, modulationScheme, noOfSymbols, x, noise,  L_ch, d, h, LLR);

      for(looping=0; looping<decoderIterations; looping++)
      {

        SPADecoder(LLR, h, LLR_ret, L_ch, L_dec, y, z);
        printf("%d\t", y[looping]);
      }

      if(z==1)											// if decoded correctly BER for that codeword is zero
      {
        BER[snr_count]=BER[snr_count]+0;

      }
      else 												// if not decoded properly calulating the BER
      {
        error_bits=0;
        for(i=0; i<COL; i++)
        {
          if(y[i]!=0)
          {
            error_bits++;

          }
        }
        errorsAccumulated+=error_bits;
        error=error_bits/(double)COL;
        BER[snr_count]=BER[snr_count]+error;
      }
      if(N%300==0)
        printf("iteration=%d \t errors accumulated=%d \n",N,errorsAccumulated);
    }

    BER[snr_count]=BER[snr_count]/(double)N; 					// averaging BER over all decoding iterations.
    printf("snr=%lf\tBER[%d]=%lf \n",snr_db[snr_count],snr_count,BER[snr_count]);

  }
  TRACE("\n** Leaving %s", __FUNCTION__);
  return 0;
}


Some output:

** Entering main
** Entering ModulationSchemeValues
** Leaving ModulationSchemeValues
** Entering InitializeChannelLLR
** Leaving InitializeChannelLLR
** Entering SPADecoder
** Entering codecheck
** codecheck(35) i = 10
** codecheck(35) i = 20
** codecheck(35) i = 30
** codecheck(35) i = 40
** codecheck(35) i = 50
** codecheck(35) i = 60
** codecheck(35) i = 70
** codecheck(35) i = 80
** codecheck(35) i = 90
** codecheck(35) i = 100
** codecheck(35) i = 110
** codecheck(35) i = 120
** codecheck(35) i = 130
** codecheck(35) i = 140
** codecheck(35) i = 150
** codecheck(35) i = 160
** codecheck(35) i = 170
** codecheck(35) i = 180
** codecheck(35) i = 190
** codecheck(35) i = 200
** codecheck(35) i = 210
** codecheck(35) i = 220
** codecheck(35) i = 230
** codecheck(35) i = 240
** codecheck(35) i = 250
** codecheck(35) i = 260
** codecheck(35) i = 270
** codecheck(35) i = 280
** codecheck(35) i = 290
** codecheck(35) i = 300
** codecheck(35) i = 310
** codecheck(35) i = 320
** codecheck(35) i = 330
** codecheck(35) i = 340
** codecheck(35) i = 350
** codecheck(35) i = 360
** codecheck(35) i = 370
** codecheck(35) i = 380
** codecheck(35) i = 390
** codecheck(35) i = 400
** codecheck(35) i = 410
** codecheck(35) i = 420
** codecheck(35) i = 430
** codecheck(35) i = 440
** codecheck(35) i = 450
** codecheck(35) i = 460
** codecheck(35) i = 470
** codecheck(35) i = 480
** codecheck(35) i = 490
** codecheck(35) i = 500
** codecheck(35) i = 510
** codecheck(35) i = 520
** codecheck(35) i = 530
** codecheck(35) i = 540
** codecheck(35) i = 550
** codecheck(35) i = 560
** codecheck(35) i = 570
** codecheck(35) i = 580
** codecheck(35) i = 590
** codecheck(35) i = 600
** codecheck(35) i = 610
** codecheck(35) i = 620
** codecheck(35) i = 630
** codecheck(35) i = 640
** codecheck(35) i = 650
** codecheck(35) i = 660
** codecheck(35) i = 670
** codecheck(35) i = 680
** codecheck(35) i = 690
** codecheck(35) i = 700
** codecheck(35) i = 710
** codecheck(35) i = 720
** codecheck(35) i = 730
** codecheck(35) i = 740
** codecheck(35) i = 750
** codecheck(35) i = 760
** codecheck(35) i = 770
** codecheck(35) i = 780
** codecheck(35) i = 790
** codecheck(35) i = 800
** codecheck(35) i = 810
** codecheck(35) i = 820
** codecheck(35) i = 830
** codecheck(35) i = 840
** codecheck(35) i = 850
** codecheck(35) i = 860
** codecheck(35) i = 870
** codecheck(35) i = 880
** codecheck(35) i = 890
** codecheck(35) i = 900
** codecheck(35) i = 910
** codecheck(35) i = 920
** codecheck(35) i = 930
** codecheck(35) i = 940
** codecheck(35) i = 950
** codecheck(35) i = 960
** codecheck(35) i = 970
** codecheck(35) i = 980
** codecheck(35) i = 990
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 996
** codecheck(35) i = 2
** codecheck(35) i = 2
** codecheck(35) i = 12
Was This Post Helpful? 0
  • +
  • -

#24 jimblumberg  Icon User is offline

  • member icon

Reputation: 5344
  • View blog
  • Posts: 16,676
  • Joined: 25-December 09

Re: Passing an array by reference in C?

Posted 01 September 2017 - 06:06 AM

Quote

I have checked the codes according to mentioned causes but eventhough i cant whats wrong in my code. Please point out location of an error. Thanks

First those are just a few of the causes of segmentation faults, there are many many more possible reasons that cause a program to crash. You should be running the program with your debugger, the debugger will be able to tell you exactly where it detects the problem and then you can view the variables at the time of the crash and then start back tracing until you discover the actual problem.

However you really should start by increasing your compiler warning levels and fixing all warnings your compiler should be detecting. Here is what my compiler says about your program.
main.c|8|warning: no previous declaration for ‘codecheck’ [-Wmissing-declarations]|
main.c|47|warning: no previous declaration for ‘codesum’ [-Wmissing-declarations]|
main.c|59|warning: no previous declaration for ‘ModulationSchemeValues’ [-Wmissing-declarations]|
main.c||In function ‘ModulationSchemeValues’:|
main.c|59|warning: parameter ‘noOfSymbols’ set but not used [-Wunused-but-set-parameter]|
main.c|59|warning: parameter ‘var’ set but not used [-Wunused-but-set-parameter]|
main.c|59|warning: parameter ‘d’ set but not used [-Wunused-but-set-parameter]|
main.c|88|warning: no previous declaration for ‘InitializeChannelLLR’ [-Wmissing-declarations]|
main.c||In function ‘InitializeChannelLLR’:|
main.c|105|warning: declaration of ‘j’ shadows a previous local [-Wshadow]|
main.c|91|note: shadowed declaration is here|
main.c|92|warning: unused variable ‘k’ [-Wunused-variable]|
main.c|88|warning: unused parameter ‘modulationScheme’ [-Wunused-parameter]|
main.c|116|warning: no previous declaration for ‘SPADecoder’ [-Wmissing-declarations]|
main.c||In function ‘main’:|
main.c|224|warning: unused variable ‘row’ [-Wunused-variable]|
main.c|224|warning: unused variable ‘ret’ [-Wunused-variable]|
main.c|214|warning: unused variable ‘temp’ [-Wunused-variable]|
main.c|205|warning: unused variable ‘sum’ [-Wunused-variable]|
main.c|205|warning: unused variable ‘t’ [-Wunused-variable]|
main.c|205|warning: unused variable ‘ber_count’ [-Wunused-variable]|
main.c|205|warning: unused variable ‘k’ [-Wunused-variable]|
main.c|205|warning: unused variable ‘j’ [-Wunused-variable]|
main.c|237|warning: ‘var’ may be used uninitialized in this function [-Wmaybe-uninitialized]|
main.c|253|warning: ‘z’ may be used uninitialized in this function [-Wmaybe-uninitialized]|


Next as you fix all of these warnings you should remove (not just comment out) all unused code in your program.

You should also be looking for code that really is not doing anything useful and determine what you really intended the code to accomplish. For example the following function doesn't actually accomplish anything:
void ModulationSchemeValues (int modulationScheme, int noOfSymbols, double var, float d, float rate, double snr)
{
	            switch (modulationScheme)
            {
                case 0:
                    //cout<<"case 0"<<endl;
                    var=1/(2*rate*snr);
                    noOfSymbols = COL;
                    d=1;
                    break;
                case 1:
                    //cout<<"case 1"<<endl;
                    var=1/(4*rate*snr);
                    noOfSymbols = COL/2;
                    d=1/sqrt(2);
                    break;
                case 2:
                    //cout<<"case 2"<<endl;
                    var=1/(8*rate*snr);
                    noOfSymbols = COL/4;
                    d=1/sqrt(10);
                default:
                    var=1/(2*rate*snr);
                    noOfSymbols = COL;
                    d=1;
                    break;
            }
}


I'll let you study the code to determine why I say it isn't doing anything.

You also need to decide what language you're trying to use and stick with that language.


Jim
Was This Post Helpful? 0
  • +
  • -

#25 thaus_15  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 53
  • Joined: 09-May 17

Re: Passing an array by reference in C?

Posted 03 September 2017 - 09:15 PM

I have fixed all errors and warning messages, but now i am getting "Segmentation Fault (SIGSEGV)" Error messages. NO Output.

#include <stdio.h>
#include <math.h>
 
#define COL 204
#define COL_P 2
#define ROWS_P 1020
 
int codecheck(int (*h)[2],int x[])
{	int i,j,m,f; //flags
	int sum = 0;
	int y[COL];
	
	for (i=0;i<COL;i++)
	y[i]=0;
	m=1;
	f=-1;
	for(i=0;i<ROWS_P;i++)							 
	{			
		for(j=0;j<COL_P;j++)
		{
			if(h[j][0]==m)
			{		
				y[m]=y[m] + x[h[j][1]-1];
					f++;
			}
		}
		y[m]=y[m]%2;
		m=m+1;
		i=f+1;
	}
 
	for (i = 0; i < COL; ++i) 
		{
			sum =sum+ y[i];
		}
	if (sum == 0) 
		{
			return 1;
		}
	else
		{	
			return -1;
		}
				
}
 
int codesum (int y[])
{
    int sum=0;
    for(int i=0;i<COL;i++)
        sum+=y[i];
    //cout<< "sum="<< sum<<endl;
    if(sum>0)
        return 0;
    else
        return 1;
}

void ModulationSchemeValues (int modulationScheme, int noOfSymbols, double var, float d, float rate, double snr)
{
	            switch (modulationScheme)
            {
                case 0:
                    //cout<<"case 0"<<endl;
                    var=1/(2*rate*snr);
                    noOfSymbols = COL;
                    d=1;
                    break;
                case 1:
                    //cout<<"case 1"<<endl;
                    var=1/(4*rate*snr);
                    noOfSymbols = COL/2;
                    d=1/sqrt(2);
                    break;
                case 2:
                    //cout<<"case 2"<<endl;
                    var=1/(8*rate*snr);
                    noOfSymbols = COL/4;
                    d=1/sqrt(10);
                default:
                    var=1/(2*rate*snr);
                    noOfSymbols = COL;
                    d=1;
                    break;
            }
}

void InitializeChannelLLR (double var, int modulationScheme, int noOfSymbols, int x[], float noise[], double L_ch[], float d, int (*h)[2], double LLR[])
{
    
    int j=0;   // temporary flags
   int k=0,t;
    for(int i=0;i<noOfSymbols;i++)							// using randnoise function introducing noise to all zero codeword
    {
        
            x[j]=d;
            noise[j]=(x[j])+0.8;
            L_ch[j]= 2*noise[j]/var;
            j++;
       
        
    }

    
    for(int j=0;j<ROWS_P;j++)
    {
        //cout<<"enter loop"<<endl;
        //cout<< "j="<<j<<endl;  //<<j<<"\t";
        t=h[j][1]-1;
        LLR[j]=L_ch[t];
    }
    //cout<<"L_ch initialize done \n";

}
 
void SPADecoder(double LLR[], int (*h)[2], double LLR_ret[], double L_ch[],  double L_dec[], int y[], int z)
{
    double temp;
	
    int i,j,k;
    for(i=0;i<ROWS_P;i++)
    {
        temp=1;
        for(j=0;j<ROWS_P;j++)
        {
            if(j!=i && h[j][0]==h[i][0])
            {
                temp=temp * tanhf(LLR[j]/2);
            }
        }
								
								
        LLR_ret[i] = log((1 + temp)/(1 - temp));     // lower and upper bounding the LLR
								
        if(LLR_ret[i] > 40)
        {
            LLR_ret[i]=40;
        }
        else if(LLR_ret[i]<-40)
        {
            LLR_ret[i]=-40;
        }
        
    }
    
    for(i=0;i<COL;i++)							// L_dec array used to decide the value of each bit of codeword here it is initalized to LLr value received from channel
    {
        L_dec[i]=L_ch[i];
    }
    
    
    for(i=1;i<COL+1;i++)						// LLR values received by the variable nodes are added and stored in L_dec for decision making
    {
        for(j=0;j<ROWS_P;j++)
        {
            if(h[j][1]==i)
            {
                L_dec[i-1]=L_dec[i-1]+LLR_ret[j];
            }
            
        }
        
        if(L_dec[i-1]<=0)						// decision about the bit values of the received codeword is done her and stored in Y.
        {
            y[i-1]=1;
        }
        else
        {
            y[i-1]=0;
        }
        
    }
    
    
    //z = codesum(y,col);
    z=codecheck(h,y); // checking whether the decoded codeword is all zero or not
    
    if(z==1)								// if decoded perfectly exit the deoding loop
    {
        return ;
    }
    // updating LLR values on variable nodes side for each variable and check node
    for(i=0;i<ROWS_P;i++)
    {
        temp=0;
        for(j=0;j<ROWS_P;j++)
        {
            if(j!=i && h[j][1]==h[i][1])
            {
                temp=temp + LLR_ret[j];
                k=h[i][1];
                
            }
        }
        LLR[i] = temp+L_ch[k-1];
    }
 
}
 
int main()
{
    
    
	// flags and counters
int z,i,j,N,k,ber_count,looping,t,sum;
    float d=1;
	float rate=0.5;
	
	int maxTransmissions=20,decoderIterations=10,maxErrors=100,errorsAccumulated=0;	
	int y[COL];	// iterations gives the maximum number of time the decoder is run for each value of SNR

    
	double var,snr;
	double temp; 								//temp variable

    
    float noise[COL];  
    double L_ch[COL],L_dec[COL];    
	double LLR[ROWS_P],LLR_ret[ROWS_P];					
	double BER[11];											
    float snr_db[]={0,1,2,3,4};
    int snr_range=5,snr_count;
	int x[]={0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,1};
    int  ret,row=0;
	double error_bits,error;
    // Set Field Separator here

    int modulationScheme = 0,noOfSymbols=204;
    
int h[ROWS_P][COL_P]={{1,1},{1,18},{1,27},{1,82},{1,102},{1,103},{1,130},{1,177},{1,190},{1,203},{2,2},{2,15},{2,75},{2,80},{2,86},{2,104},{2,121},{2,141},{2,144},{2,191},{3,3},{3,31},{3,32},{3,42},{3,101},{3,105},{3,153},{3,159},{3,178},{3,199},{4,4},{4,37},{4,71},{4,75},{4,85},{4,106},{4,111},{4,114},{4,127},{4,164},{5,5},{5,17},{5,42},{5,72},{5,87},{5,107},{5,141},{5,158},{5,193},{5,197},{6,4},{6,6},{6,17},{6,78},{6,102},{6,108},{6,162},{6,165},{6,167},{6,174},{7,7},{7,23},{7,73},{7,80},{7,83},{7,109},{7,118},{7,168},{7,177},{7,178},{8,8},{8,33},{8,37},{8,73},{8,100},{8,110},{8,156},{8,173},{8,192},{8,197},{9,9},{9,40},{9,41},{9,88},{9,92},{9,103},{9,111},{9,173},{9,181},{9,199},{10,10},{10,14},{10,23},{10,53},{10,93},{10,107},{10,112},{10,137},{10,167},{10,175},{11,11},{11,19},{11,26},{11,28},{11,88},{11,110},{11,113},{11,116},{11,170},{11,191},{12,1},{12,12},{12,25},{12,86},{12,97},{12,108},{12,114},{12,124},{12,161},{12,192},{13,4},{13,13},{13,33},{13,34},{13,50},{13,115},{13,137},{13,140},{13,146},{13,160},{14,14},{14,31},{14,40},{14,58},{14,95},{14,116},{14,121},{14,166},{14,174},{14,203},{15,15},{15,68},{15,70},{15,87},{15,101},{15,109},{15,113},{15,117},{15,165},{15,180},{16,4},{16,16},{16,59},{16,67},{16,92},{16,118},{16,125},{16,131},{16,138},{16,151},{17,15},{17,17},{17,44},{17,71},{17,73},{17,119},{17,161},{17,190},{17,194},{17,198},{18,18},{18,47},{18,62},{18,85},{18,93},{18,120},{18,122},{18,125},{18,146},{18,181},{19,19},{19,22},{19,23},{19,37},{19,57},{19,121},{19,126},{19,130},{19,131},{19,143},{20,1},{20,20},{20,50},{20,51},{20,99},{20,106},{20,122},{20,169},{20,179},{20,200},{21,21},{21,32},{21,62},{21,72},{21,98},{21,123},{21,126},{21,154},{21,168},{21,204},{22,22},{22,31},{22,44},{22,89},{22,98},{22,124},{22,141},{22,160},{22,169},{22,176},{23,23},{23,32},{23,61},{23,65},{23,99},{23,125},{23,132},{23,133},{23,147},{23,152},{24,16},{24,24},{24,42},{24,73},{24,77},{24,126},{24,142},{24,145},{24,146},{24,147},{25,5},{25,24},{25,25},{25,55},{25,67},{25,127},{25,133},{25,165},{25,178},{25,185},{26,10},{26,26},{26,27},{26,40},{26,85},{26,128},{26,147},{26,155},{26,160},{26,200},{27,22},{27,27},{27,42},{27,50},{27,74},{27,108},{27,129},{27,154},{27,170},{27,195},{28,2},{28,28},{28,63},{28,67},{28,94},{28,130},{28,150},{28,171},{28,187},{28,192},{29,29},{29,48},{29,69},{29,79},{29,90},{29,116},{29,131},{29,159},{29,176},{29,200},{30,7},{30,30},{30,53},{30,58},{30,94},{30,127},{30,132},{30,140},{30,162},{30,189},{31,29},{31,31},{31,64},{31,77},{31,94},{31,117},{31,133},{31,167},{31,183},{31,190},{32,20},{32,30},{32,32},{32,74},{32,78},{32,115},{32,134},{32,151},{32,181},{32,194},{33,11},{33,33},{33,47},{33,76},{33,81},{33,109},{33,135},{33,154},{33,155},{33,179},{34,2},{34,7},{34,34},{34,71},{34,76},{34,136},{34,138},{34,159},{34,182},{34,183},{35,27},{35,29},{35,35},{35,60},{35,86},{35,123},{35,137},{35,149},{35,166},{35,189},{36,17},{36,35},{36,36},{36,48},{36,100},{36,138},{36,139},{36,146},{36,163},{36,168},{37,5},{37,34},{37,37},{37,38},{37,69},{37,117},{37,139},{37,145},{37,169},{37,203},{38,38},{38,56},{38,76},{38,92},{38,101},{38,106},{38,123},{38,140},{38,161},{38,170},{39,39},{39,41},{39,60},{39,76},{39,78},{39,125},{39,141},{39,142},{39,175},{39,198},{40,2},{40,35},{40,40},{40,43},{40,93},{40,114},{40,135},{40,142},{40,148},{40,158},{41,1},{41,2},{41,13},{41,41},{41,59},{41,109},{41,119},{41,132},{41,143},{41,157},{42,11},{42,42},{42,43},{42,92},{42,95},{42,115},{42,117},{42,144},{42,156},{42,204},{43,7},{43,9},{43,43},{43,45},{43,56},{43,122},{43,145},{43,192},{43,194},{43,201},{44,10},{44,44},{44,75},{44,83},{44,95},{44,110},{44,135},{44,146},{44,157},{44,180},{45,45},{45,63},{45,79},{45,81},{45,97},{45,127},{45,139},{45,147},{45,148},{45,195},{46,34},{46,46},{46,61},{46,66},{46,77},{46,105},{46,144},{46,148},{46,197},{46,201},{47,14},{47,20},{47,46},{47,47},{47,83},{47,124},{47,128},{47,132},{47,149},{47,159},{48,8},{48,13},{48,26},{48,48},{48,62},{48,149},{48,150},{48,174},{48,193},{48,195},{49,15},{49,21},{49,25},{49,49},{49,51},{49,145},{49,149},{49,151},{49,177},{49,188},{50,8},{50,49},{50,50},{50,54},{50,89},{50,105},{50,126},{50,152},{50,164},{50,165},{51,43},{51,51},{51,66},{51,68},{51,91},{51,131},{51,133},{51,153},{51,187},{51,189},{52,1},{52,39},{52,45},{52,52},{52,54},{52,110},{52,140},{52,150},{52,154},{52,163},{53,8},{53,53},{53,60},{53,64},{53,90},{53,138},{53,155},{53,157},{53,194},{53,204},{54,12},{54,28},{54,54},{54,60},{54,82},{54,112},{54,139},{54,151},{54,156},{54,183},{55,3},{55,17},{55,37},{55,55},{55,99},{55,112},{55,148},{55,157},{55,172},{55,189},{56,20},{56,31},{56,56},{56,80},{56,91},{56,152},{56,156},{56,158},{56,162},{56,180},{57,28},{57,57},{57,66},{57,81},{57,89},{57,134},{57,137},{57,159},{57,172},{57,196},{58,5},{58,58},{58,70},{58,78},{58,91},{58,118},{58,149},{58,154},{58,160},{58,201},{59,18},{59,24},{59,59},{59,88},{59,96},{59,150},{59,152},{59,161},{59,179},{59,183},{60,21},{60,38},{60,55},{60,59},{60,60},{60,162},{60,176},{60,187},{60,190},{60,197},{61,61},{61,69},{61,74},{61,93},{61,101},{61,111},{61,128},{61,163},{61,193},{61,196},{62,6},{62,7},{62,35},{62,62},{62,96},{62,103},{62,113},{62,129},{62,164},{62,200},{63,16},{63,27},{63,44},{63,63},{63,88},{63,121},{63,134},{63,165},{63,175},{63,188},{64,4},{64,26},{64,64},{64,79},{64,84},{64,119},{64,134},{64,136},{64,166},{64,168},{65,12},{65,13},{65,52},{65,57},{65,65},{65,106},{65,138},{65,142},{65,167},{65,176},{66,24},{66,30},{66,52},{66,66},{66,102},{66,112},{66,117},{66,122},{66,135},{66,168},{67,6},{67,57},{67,67},{67,85},{67,97},{67,140},{67,169},{67,182},{67,184},{67,186},{68,6},{68,58},{68,68},{68,71},{68,90},{68,134},{68,143},{68,145},{68,152},{68,170},{69,54},{69,57},{69,59},{69,69},{69,77},{69,103},{69,104},{69,114},{69,136},{69,171},{70,19},{70,24},{70,56},{70,70},{70,100},{70,105},{70,114},{70,128},{70,129},{70,172},{71,14},{71,52},{71,63},{71,70},{71,71},{71,120},{71,169},{71,173},{71,178},{71,196},{72,11},{72,25},{72,39},{72,66},{72,72},{72,120},{72,130},{72,132},{72,174},{72,199},{73,48},{73,49},{73,64},{73,73},{73,98},{73,111},{73,175},{73,179},{73,201},{73,202},{74,9},{74,15},{74,58},{74,74},{74,84},{74,107},{74,120},{74,135},{74,164},{74,176},{75,28},{75,41},{75,70},{75,75},{75,96},{75,133},{75,155},{75,166},{75,177},{75,202},{76,26},{76,45},{76,65},{76,76},{76,94},{76,144},{76,158},{76,172},{76,178},{76,203},{77,10},{77,13},{77,77},{77,84},{77,87},{77,127},{77,151},{77,163},{77,179},{77,191},{78,49},{78,55},{78,65},{78,78},{78,90},{78,122},{78,130},{78,139},{78,180},{78,182},{79,33},{79,43},{79,67},{79,79},{79,99},{79,123},{79,141},{79,181},{79,188},{79,202},{80,18},{80,19},{80,35},{80,46},{80,80},{80,153},{80,167},{80,182},{80,188},{80,193},{81,9},{81,16},{81,36},{81,55},{81,81},{81,143},{81,160},{81,183},{81,186},{81,191},{82,10},{82,11},{82,79},{82,82},{82,96},{82,108},{82,111},{82,126},{82,172},{82,184},{83,12},{83,36},{83,69},{83,83},{83,87},{83,148},{83,174},{83,185},{83,202},{83,204},{84,45},{84,47},{84,48},{84,75},{84,84},{84,108},{84,123},{84,142},{84,153},{84,186},{85,9},{85,46},{85,53},{85,54},{85,85},{85,115},{85,121},{85,129},{85,177},{85,187},{86,22},{86,64},{86,83},{86,86},{86,91},{86,107},{86,116},{86,171},{86,188},{86,199},{87,8},{87,22},{87,61},{87,81},{87,87},{87,104},{87,120},{87,182},{87,189},{87,198},{88,32},{88,33},{88,39},{88,51},{88,88},{88,129},{88,143},{88,171},{88,180},{88,190},{89,3},{89,21},{89,52},{89,89},{89,100},{89,103},{89,109},{89,115},{89,125},{89,191},{90,20},{90,40},{90,44},{90,61},{90,90},{90,118},{90,137},{90,153},{90,184},{90,192},{91,6},{91,23},{91,29},{91,84},{91,91},{91,144},{91,155},{91,173},{91,185},{91,193},{92,14},{92,49},{92,72},{92,92},{92,102},{92,147},{92,171},{92,185},{92,186},{92,194},{93,5},{93,21},{93,29},{93,65},{93,93},{93,105},{93,110},{93,119},{93,184},{93,195},{94,39},{94,80},{94,82},{94,94},{94,98},{94,107},{94,113},{94,131},{94,166},{94,196},{95,30},{95,47},{95,50},{95,63},{95,95},{95,104},{95,118},{95,161},{95,163},{95,197},{96,25},{96,34},{96,56},{96,68},{96,96},{96,116},{96,181},{96,186},{96,196},{96,198},{97,36},{97,38},{97,46},{97,89},{97,97},{97,113},{97,136},{97,150},{97,157},{97,199},{98,3},{98,12},{98,18},{98,30},{98,98},{98,136},{98,170},{98,187},{98,198},{98,200},{99,53},{99,62},{99,74},{99,97},{99,99},{99,104},{99,119},{99,156},{99,185},{99,201},{100,16},{100,68},{100,82},{100,95},{100,100},{100,106}};
 
                 for(snr_count=0;snr_count<snr_range;snr_count++)
	{
      //  cout<<"Decoder run for SNR in db=" <<snr_db[snr_count]<<endl;
				snr=pow(10,(snr_db[snr_count]/10));
				
				ModulationSchemeValues (modulationScheme, noOfSymbols, var, d, rate, snr);  // determining various values based on mdulation scheme
        
        							// calulating noise variance from SNR
				BER[snr_count]=0;									// initializing BER
             //   normal_distribution<double> dist(0.0, 1);
                N=0;
                errorsAccumulated=0;
					while(errorsAccumulated<=maxErrors && N<=maxTransmissions)
					{		
                        N++;
                        
                        InitializeChannelLLR( var, modulationScheme, noOfSymbols, x, noise,  L_ch, d, h, LLR);
                        
                        for(looping=0;looping<decoderIterations;looping++)
						{
							
                            SPADecoder(LLR, h, LLR_ret, L_ch, L_dec, y, z);
                     printf("%d\t", y[looping]);
						}
										
							if(z==1)											// if decoded correctly BER for that codeword is zero
								{
									BER[snr_count]=BER[snr_count]+0;

								}
							else 												// if not decoded properly calulating the BER
								{		
									error_bits=0;
									for(i=0;i<COL;i++)
									{
										if(y[i]!=0)
										{
											error_bits++;
											
										}
									}
                                    errorsAccumulated+=error_bits;
                                    error=error_bits/(double)COL;
									BER[snr_count]=BER[snr_count]+error;
								}
                   if(N%300==0)
                printf("iteration=%d \t errors accumulated=%d \n",N,errorsAccumulated);
					}
					
				BER[snr_count]=BER[snr_count]/(double)N; 					// averaging BER over all decoding iterations.
					printf("snr=%lf\tBER[%d]=%lf \n",snr_db[snr_count],snr_count,BER[snr_count]);
				
	}
		return 0;
}





Please point the error.
Was This Post Helpful? 0
  • +
  • -

#26 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5922
  • View blog
  • Posts: 20,247
  • Joined: 05-May 12

Re: Passing an array by reference in C?

Posted 04 September 2017 - 05:03 AM

As we told you before, use a debugger. Using us to debug by proxy is not productive use of your time, although it may amuse some of the volunteers on this forum looking to kill some time.
Was This Post Helpful? 0
  • +
  • -

#27 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5922
  • View blog
  • Posts: 20,247
  • Joined: 05-May 12

Re: Passing an array by reference in C?

Posted 04 September 2017 - 06:20 AM

Anyway, taking a quick look at your new code, your functions take int (*h)[2]. This means an array of 2 pointers to integers. You are passing in a 2 dimensional array of integers, though.
Was This Post Helpful? 1
  • +
  • -

#28 jimblumberg  Icon User is offline

  • member icon

Reputation: 5344
  • View blog
  • Posts: 16,676
  • Joined: 25-December 09

Re: Passing an array by reference in C?

Posted 04 September 2017 - 06:34 AM

Quote

I have fixed all errors and warning messages, but now i am getting "Segmentation Fault (SIGSEGV)" Error messages. NO Output.

No you haven't. You haven't fixed any of the issues I pointed out in my last post and several of those issues are probably the cause of most of your problems.

And ModulationSchemeValues() is still not accomplishing anything, do you understand why?

Quote

your functions take int (*h)[2]. This means an array of 2 pointers to integers.

Not really, remember that *h[2] is the same as h[][2].

Jim

This post has been edited by jimblumberg: 04 September 2017 - 06:47 AM

Was This Post Helpful? 1
  • +
  • -

#29 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2517
  • View blog
  • Posts: 4,001
  • Joined: 21-June 11

Re: Passing an array by reference in C?

Posted 04 September 2017 - 06:46 AM

View PostSkydiver, on 04 September 2017 - 03:20 PM, said:

Anyway, taking a quick look at your new code, your functions take int (*h)[2]. This means an array of 2 pointers to integers.


That'd be int *h[2]. int (*h)[2] is a pointer to a two-element array of integers.
Was This Post Helpful? 1
  • +
  • -

#30 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5922
  • View blog
  • Posts: 20,247
  • Joined: 05-May 12

Re: Passing an array by reference in C?

Posted 04 September 2017 - 01:45 PM

Good catch. I really shouldn't be online with all this cold medicine in my system... but the boredom is terrible.
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4