tags:

views:

285

answers:

3

I am a beginer in programming. unfortunately I have a project in c++ that I don't know its problem. the program is a little long:

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <alloc.h>
#include <time.h>
#include <math.h>
#include "vdsim.h"
void gen01dat( long, int);
void cnv_encd(int g[], long,int,int);
int main()
{
long data_len=10;
int *out_array;
long input_len=5;
int g[2][3];

    void gen01dat(data_len,*out_array);

    int in_array=*out_array;
  void cnv_encd(g,input_len,in_array,*out_array);
  cout<<"the out_array 2 is :\t"<<*out_array<<endl;


  void gen01dat( long data_len, int *out_array ) {

     long t;            /* time */

     /* re-seed the random number generator */
     randomize();

     /* generate the random data and write it to the output array */
     for (t = 0; t < data_len; t++)
       *( out_array + t ) = (int)( rand() / (RAND_MAX / 2) > 0.5 );

}

void cnv_encd(int g[2][k],long input_len, int *in_array,int *out_array)
{

     int m;                     /* K - 1 */
     long t, tt;                /* bit time, symbol time */
     int j, k;                  /* loop variables */
     int *unencoded_data;       /* pointer to data array */
     int shift_reg[K];          /* the encoder shift register */
     int sr_head;               /* index to the first elt in the sr */
     int p, q;                  /* the upper and lower xor gate outputs */

     m = K - 1;

     /* read in the data and store it in the array */
     for (t = 0; t < input_len; t++)
       *(unencoded_data + t) = *(in_array + t);

     /* zero-pad the end of the data */
     for (t = 0; t < m; t++) {
       *(unencoded_data + input_len + t) = 0;
     }

     /* Initialize the shift register */
     for (j = 0; j < K; j++) {
       shift_reg[j] = 0;
     }

     sr_head = 0;

     /* initialize the channel symbol output index */
     tt = 0;

     for (t = 0; t < input_len + m; t++) {
       shift_reg[sr_head] = *( unencoded_data + t );
       p = 0;
       q = 0;
       for (j = 0; j < K; j++) {
       k = (j + sr_head) % K;
       p ^= shift_reg[k] & g[0][j];
       q ^= shift_reg[k] & g[1][j];
       }

       /* write the upper and lower xor gate outputs as channel symbols */
       *(out_array + tt) = p;
       tt = tt + 1;
       *(out_array + tt) = q;
       tt = tt + 1;


       sr_head -= 1;    /* equivalent to shifting everything right one place */
       if (sr_head < 0) /* but make sure we adjust pointer modulo K */
       sr_head = m;

     }

     /* free the dynamically allocated array */
     free(unencoded_data);

}

    return 0;
}

the compiler gives this error:

error: size of 'gen01'is unknown or zero in function main()
error: size of 'cnv_encd'is unknown or zero in function main()

I don't know this what does this error mean? thanks for your help

+13  A: 

You can't nest functions in C++, so try moving the definitions of cnv_encd() and gen01dat() out of main().

Also, you are calling the functions wrongly:

void gen01dat(data_len,*out_array);

should be

gen01dat(data_len,out_array);

and you do not initialise out_array before you use it (this is not a compile error, but it will make your program crash).

Your call to cnv_encd() is similarly wrong. Also you declare cnv_encd() to take different parameters in different places: compare the declaration before main() to the definition you give later on.

Dave Hinton
+3  A: 

You are trying to call gen01dat & cnv_encd functions in main. However, your calling syntax is wrong.

void gen01dat(data_len,*out_array);

should just be

gen01dat(data_len,*out_array);

The same follows for the other function call also.

Looking at your code, even after you fix those, you are going to run into other warnings or errors. But since you are learning, I will let you figure them out for yourself.

Update: I did not see the nested functions within the main. Thats wrong too. Though, I suspect the missing closing brace is a typo.

Aditya Sehgal
Actually, I think that's the definition of the functions there, not a call to them.
marcc
There is a declaration just after #includes, so I guess he understands what a declaration is. Then he tries to IMO, call them by giving the actual parameters. The actual definition follows a little down. If you see the code, I think the OP is just missing a closing brace to signify the end of main.
Aditya Sehgal
The `return 0;` and closing brace of `main()` are after the definitions of the two other functions.
Dave Hinton
+1  A: 

the "void" keyword is only use when declaring a function. It tells the compiler that this function doesn't return any value.

So you only use it when declaring your functions and when implementing them. When you call them you just use it's name and arguments. Just like Aditya Sehgal pointed.

And you need to change your declarations. They must have the argument variable names in it, and not just the type of the variables.

rogeriopvl
We can use "void" while calling a function too. Something like (void)Function();
Aditya Sehgal
Also when declaring a pointer.
Daniel Earwicker