Hi all
I tried to run this code on C and I m gettin this error can anyone help me solve it ?
also what is an intializer in C? what does it mean when the error says in line 5 about expected intializer before C?
"C:\TurboCPP\c_work\DECQDER3.C|5|error: expected initializer before "int"|
C:\TurboCPP\c_work\DECQDER3.C||In function `void trellis_builder(char*, int)':|
C:\TurboCPP\c_work\DECQDER3.C|277|error: `next_state' was not declared in this scope|
C:\TurboCPP\c_work\DECQDER3.C|299|error: `next_state' was not declared in this scope|
||=== Build finished: 3 errors, 0 warnings ===|
"
my code is pasted below.
Thanks fo rthe help.
#include "myhead.h"
int main()
int next_state[8][2]= {0,4,
0,4,
1,5,
1,5,
2,6,
2,6,
3,7,
3,7};
int output_table[8][2]={0,15,
15,0,
9,6,
6,9,
7,8,
8,7,
14,1,
1,14};
int input_table[8][8]={0,2,2,2,1,2,2,2,
0,2,2,2,1,2,2,2,
2,0,2,2,2,1,2,2,
2,0,2,2,2,1,2,2,
2,2,0,2,2,2,1,2,
2,2,0,2,2,2,1,2,
2,2,2,0,2,2,2,1,
2,2,2,0,2,2,2,1};
int state_history[8][21];
int state_sequence[20];
int branch_metric[8][2];
int path_metric[8][2];
int prev_state[8][2];
int minimum();
void trellis_builder(char * output,int time);
int branch_metric_calc(int,int,char *);
void dec () {
FILE * fp;
FILE * op, *f3;
char output_symbol[5];
char ch;
char output_ch;
int ro,i,j,track;
int time_count=0;
int pr_num, pr_den,a,z,b,c,x,r_vbc;
int time=0;
int min_err_pos;
int count=19;
int p_vbc[40][40];
int output;
int first=1;
state_history[0][0]=0;
pr_num=1;
pr_den=4;
a=8/pr_num;
b=pr_num*a;
c=pr_den*a;
// r_lbc=c*7/8;
f3=fopen("levels.txt","r");
fscanf(f3,"%d %d",&x,&z);
printf("\nx z:%d %d",x,z);
// getch();
fclose(f3);
// r_vbc=c*6/8;
r_vbc=z;
printf("a b c r_vbc %d %d %d %d", a, b, c, r_vbc);
// getch();
x=0;
for (i=0;i<40;i++)
for (j=0;j<40;j++)
p_vbc[i][j]=0;
for (i=0;i<pr_den;i++)
{
for (j=0;j<b;j++)
{
if (x<r_vbc)
{
p_vbc[i][j]=1;
x++;
}
else
p_vbc[i][j]=0;
}
}
for (i=0;i<pr_den;i++)
{
for (j=0;j<b;j++)
printf("%d ",p_vbc[i][j]);
printf("\n");
}
// getch();
for(i=0;i<8;i++) {
for(j=0;j<21;j++) {
if(i==0 && j==0)
continue;
state_history[i][j]=8;
}
}
fp=fopen("errout.txt","r");
op=fopen("decodero.txt","w");
ro=0;
track=0;
for (j=0;(!feof(fp));j++)
// while(!feof(fp)) {
// for(i=0;i<3;i++) {
{
if (p_vbc[(j%4)][(ro%8)]==1)
{
ch=fgetc(fp);
if(ch==EOF) {
for(i=0;i<20;i++) {
if(i==19)
break;
else {
output=input_table[state_sequence[i]][state_sequence[i+1]];
itoa(output,&output_ch,2);
fputc(output_ch,op);
}
}
fclose(fp);
fclose(op);
printf("\nfile closed");
// getch();
return;
}
output_symbol[track]=ch;
track++;
}
else
{
output_symbol[track]='2';
track++;
}
if (track<4)
continue;
output_symbol[track]='\0';
track=0;
ro++;
trellis_builder(output_symbol,time_count);
printf("Time: %d\n",time++);
printf("State History\n");
for(i=0;i<8;i++)
printf("%d ",state_history[i][time_count]);
printf("\n");
printf("Branch error\n");
for(i=0;i<8;i++) {
printf("%d",branch_metric[i][0]);
printf("%d ",branch_metric[i][1]);
}
printf("\n");
printf("Path error\n");
for(i=0;i<8;i++)
printf("%d ",path_metric[i][0]);
printf("\n");
printf("Previous State\n");
for(i=0;i<8;i++) {
printf("%d",prev_state[i][0]);
printf("%d ",prev_state[i][1]);
}
printf("\n");
if(time_count>19) {
if(first) {
first=0;
min_err_pos=minimum();
for(i=20;i>0;i--) {
state_sequence[count]=state_history[min_err_pos][i];
min_err_pos=state_sequence[count];
count--;
}
}
else {
min_err_pos=minimum();
state_sequence[19]=state_history[min_err_pos][time_count];
}
printf("Trace back Path:\n");
for(i=0;i<20;i++)
printf("%d ",state_sequence[i]);
printf("\n");
for(i=0;i<8;i++) {
for(j=0;j<21;j++)
state_history[i][j]=state_history[i][j+1];
}
output=input_table[state_sequence[0]][state_sequence[1]];
itoa(output,&output_ch,2);
printf("Output : %d %c\n",output,output_ch);
fputc(output_ch,op);
for(i=0;i<=19;i++) {
if(i==19)
break;
else
state_sequence[i]=state_sequence[i+1];
}
}
if(time_count<=19)
time_count++;
}
}
void trellis_builder(char * output_sym,int time) {
int i,j;
int nextstate;
int prevstate=0;
int error;
int temp;
int temp1,temp2;
int err1,err2;
// printf("Time %d\n",time);
for(i=0;i<8;i++) {
if(time==0)
break;
if(state_history[i][time]<8) {
temp=prev_state[i][0];
path_metric[i][1]=path_metric[temp][0]+branch_metric[i][0];
}
if(time>3) {
temp1=prev_state[i][0];
temp2=prev_state[i][1];
err1=path_metric[temp1][0]+branch_metric[i][0];
err2=path_metric[temp2][0]+branch_metric[i][1];
if(err1<err2) {
path_metric[i][1]=err1;
state_history[i][time]=temp1;
}
else {
path_metric[i][1]=err2;
state_history[i][time]=temp2;
}
}
}
for(i=0;i<8;i++) {
prev_state[i][0]=0;
prev_state[i][1]=0;
branch_metric[i][0]=0;
branch_metric[i][1]=0;
}
for(i=0;i<8;i++) {
if(state_history[i][time]<8) {
for(j=0;j<2;j++) {
if(time>=3) {
nextstate=next_state[i][j];
error=branch_metric_calc(i,j,output_sym);
if(prev_state[nextstate][0]) {
prev_state[nextstate][1]=i;
branch_metric[nextstate][1]=error;
}
else {
if(i==1 && j==0 || i==1 && j==1) {
prev_state[nextstate][1]=i;
branch_metric[nextstate][1]=error;
}
else {
prev_state[nextstate][0]=i;
branch_metric[nextstate][0]=error;
}
}
}
else {
nextstate=next_state[i][j];
prev_state[nextstate][0]=i;
error=branch_metric_calc(i,j,output_sym);
branch_metric[nextstate][0]=error;
state_history[nextstate][time+1]=i;
}
}
}
}
for(i=0;i<8;i++) {
if(time==0)
break;
path_metric[i][0]=path_metric[i][1];
}
}
int branch_metric_calc(int curr_state,int input,char * symbol) {
int i,j;
int ref_output;
int count=3;
int errcount=0;
char ch;
ref_output=output_table[curr_state][input];
for(j=0;j<4;j++) {
ch=symbol[count];
//if (ch=='2')
//errcount+=2;
i=ch-'0';
if(!(ref_output%2==i))
errcount++;
ref_output=ref_output/2;
count--;
}
return errcount;
}
int minimum() {
int min=0;
int min_pos=0;
int i;
for(i=0;i<8;i++) {
if(i==0) {
min=path_metric[i][0];
min_pos=i;
}
else if((path_metric[i][0]<min)&&(path_metric[i][0]>=0)) {
min=path_metric[i][0];
min_pos=i;
}
}
printf("Min value: %d Min position: %d\n",min,min_pos);
return min_pos;
}