Newsgroup: it.comp.lang.c++
Titolo: load array

My question is quite simple I know. I need to load some samples to an array
by use of a function. I have the two programs, but don't know how to combine
them. C++ is not my strong point to say the least!!!
Then I need to find the average of theses samples. The samples are just an S
record file which is already supplied.
Q1 & 2:
load_samples(  ) This is pased a single parameter: an array in which a
waveform will be stored. It reads the values to be placed in the array from
locations 0x4000 onwards. The first 16 bit number is the count of the number
of values stored in the table. This is followed by the 16 bit samples. Note
that the waveform used will not contain more than 1024 samples. The function
returns the count of the number of samples (as a 16 bit integer).
find_average ( ) This is passed two parameters: an array in which the
waveform is stored and a count of the number of samples in the waveform. It
returns the average value (as a short) of the values held in the array.
I am just so crap at this!!!!!!
Thanks,
Gavin.
 * Description: This is the solution for Computer-Based
 *              Instrumentation Systems, Lab S3.
 *
 *              It involves signal processing on digital signals held in
arrays
 * of 16 bit integers. The average value and the number of zero crossings in
 * the waveforms will be calculated. The waveforms will be rectified and
 * clipped. The samples will be sent to a 12-bit DAC so that the waveforms
can
 * be displayed on an oscilloscope.
 *
****************************************************************************
*/
#define MAX         1024        /* Maximum number of readings */
#define BASE_ADDR   0x4000     /* Base address of data in memory */
#define RESULT_ADDR 0x4c00     /* Base address of results in memory */
#define AVERAGE_ADDR 0x4c10    /* Address of sensor number in memory */
#define END         0x6000     /* End of data marker */
int main()
{
      short   readings[MAX];                   /* Data read from memory */
 short   *number = (short *)  RESULT_ADDR; /* Ptr. to no. of readings taken
*/
 short   *average = (short *) 0X4C02;     /* Find the average of the
values*/
 short   *result = (short *)  0x4c04;      /* held in the array*/
      short   load_samples(short data[]);
 short   find_average(short data[], short num_readings);
      /* Load readings into array */
 *number = load_samples(readings);
 /* Load readings into array */
 *average = find_average(readings, *number);
     return(0);
}
/***************************************************************************
***
 *
 * Name:        load_array
 * Parameters:  data - array of readings
 * Returns:     number of samples read from memory
 * Globals:     none
 * Description: Reads event information (as 16-bit words) from locations
 *              onwards until the hex value 6000 is encountered.  It returns
 *              a count of the number of words read.
 *
****************************************************************************
*/
short load_samples(short data[])
{
    short   count = 0;                  /* Number of samples taken */
    short   *ptr = (short *) BASE_ADDR; /* Pointer to readings in memory */
    /* Read data until End of Data value is found */
    while (*ptr != END)
    {
        data[count] = *ptr++;        /* Read next value into array */
        count++;                     /* Increment count of readings taken */
    }
    return(count);
}
/***************************************************************************
***
 *
 * Name:        find_average
 * Parameters:  data - array of samples
 * Returns:     returns the average value of the values held in the array
 * Globals:     none
 * Description: This function is passed two parameters: an array in which
the
 * waveform is stored and a count of the number of samples in the waveform.
It
 * returns the average value (as a short) of the values held in the array.
 *
****************************************************************************
*/
short find_average(short data[], short num_samples)
{
  unsigned short count = 0;
   unsigned short i;
 for (i = 0; i < num_readings; i++)
 {
   if ((data[i] & 0x8000) == 0x8000)
  {
       count +=1;
  }
 }
 return (count);
}
* Description:
* This C program reads the contents of addresses from 0x4800 onward and
* counts the number of zeros in the table and puts the number into address
* location 0x3ffe. The size of the table is read from address location
* 0x4800.
***************************************************************************/
int main()
{
  unsigned short *result = (unsigned short *)0x3ffe;
  unsigned short count = 0;
   unsigned short *address = (unsigned short *)0x4800;
 unsigned short i;
 *result =0;
 count = *address++;
 for (i = 0; i < count; i++)
 {
   if (*address++ == 0x0000)
  {
       *result +=1;
  }
 }
 return (count);
}

Ma nelle universitŕ straniere non progettavano sistemi operativi?
Dai che tutto il mondo č paese... :-)