ok..first of all i am sorry i didn't post them before, it was just that i didnt' have them in hand.....note:i created a data file for each program..for the first one i created Sensor1.dat and sec..sensor2.dat and thi...sensor3.dat...one more thing...i try to paste them as neatly as i could
"Counter"
-----------*/
/* assignment2 */
/* this program generates a summary report from
a data file that has the number of data points
in the first record; */
#include <stdio.h>
#define FILENAME "sensor1.dat"
int main (void)
{
/* declare and initialize variables. */
int num_data_pts, k;
double time, motion, sum=0, max, min;
FILE * sensor1;
/* open file and read the number of data points. */
sensor1 = fopen (FILENAME, "r");
if (sensor1==NULL)
{
printf("error opening input file\n");
}
else
{
fscanf(sensor1,"%i",&num_data_pts);
/* read data and compute summary information. */
for (k=1; k<=num_data_pts; k++)
{
fscanf (sensor1,"%i %f",&time,&motion);
if (k == 1)
max = min = motion;
sum += motion;
if (motion > max)
max=motion;
if (motion< min)
min = motion;
}
/* print summary information. */
printf("number of sensor readings: %i \n",
num_data_pts);
printf ("Max : %i \n", max);
printf ("Min : %i \n", min);
/* close file and exit porgram. */
fclose (sensor1);
}
return 0;
}
------------*/
Sentinel:
-------------*/
/* assignment2 */
/* this program generates a summary report from */
/* a data file that has the number of data points */
/* in the first record; */
#include <stdio.h>
#define FILENAME "sensor2.dat"
int main (void)
{
/* declare and initialize variables. */
int num_data_pts=0, k;
double time, motion, sum=0, max, min;
FILE * sensor2;
/* open file and read the first data point. */
sensor2 = fopen (FILENAME, "r");
if (sensor2 == NULL)
{
printf("error opening input file\n");
}
else
{
fscanf(sensor2,"%i %f", &time,&motion);
/* initialize variables using first data point. */
max = min = motion;
/* update summary data until trailer record read. */
do
{
sum += motion;
if (motion > max)
max = motion;
if (motion < min)
min = motion;
num_data_pts++;
fscanf (sensor2,"%i %f", &time,&motion);
} while (time >= 0);
/* print summary information. */
printf("number of sensor readings: %i \n",
num_data_pts);
printf ("Max : %i \n", max);
printf ("Min : %i \n", min);
/* close file and exit porgram. */
fclose (sensor2);
}
return 0;
}
------------*/
i don't know how to call this program, but it isn't sentinel nor counter as you might already know:
--------------*/
/* assignment_2 */
/* */
/* this program generates a summary report from a data file that */
/* has the number of data points in the first record */
#include <stdio.h>
#define FILENAME "sensor3.dat"
int main (void)
{
/* Declare and initialize variables. */
int num_data_pts=0, k;
double time, motion, sum=0, max, min;
FILE *sensor3;
/* open file */
sensor3= fopen (FILENAME, "r");
if (sensor3 == NULL)
{
Printf (" Error opening input file \n");
}
else
{
/* while not at the end of the file. */
/* read and accumulate information */
while ((fscanf (sensor3, "%i %f", &time,&motion)) == 2)
{
num_data_pts++;
if (num_data_pts == 1)
max = min = motion;
sum += motion;
if (motion > max)
max = motion;
if (motion < min)
min = motion;
}
/* print summary information. */
printf ("Number of sensor readings: %i \n",
num_data_pts);
printf (" Max : %i \n", max);
printf (" Min : %i \n", min);
/* close file and exit program. */
fclose (sensor3);
}
return 0;
}
---------------------*/
chech them only if you have time please. and if you can't...then that's also ok...
Noe