Пример #1
0
/**
   Create a record of a speeding incident
   and scan the relevant data from the file pointer fp,
   in this format:

   2/3/2005 3:45 87.6 JJJ 472

   @param  fp file pointer to read from
   @return pointer to newly created speeding incident
*/
Speeding * scan_speeding( FILE *fp )
{
  Speeding * new_speeding = (Speeding *)malloc(sizeof(Speeding));

  if( new_speeding != NULL ) {
    if(  ( scan_date( &new_speeding->date, fp ))
       &&( scan_time( &new_speeding->time, fp ))
       && fscanf( fp,"%lf", &new_speeding->speed )
       && fgets( new_speeding->plate, MAX_PLATE, fp )) {
      return( new_speeding );
    }
    else {
      free( new_speeding );
    }
  }

  return( NULL );
}
Пример #2
0
struct auto_t scan_auto(char *line) {
    int spacesCount = 0;
    int i, endOfMake, endOfModel, endOfOdometer;
    char newLine[1000];
    for (i = 0; i < sizeof(line); i++) {
        if (line[i] == ' ') {
            spacesCount++;
            if (spacesCount == 1) {
                endOfMake = i;
            }
            else if (spacesCount == 2) {
                endOfModel = i;
            }
            else if (spacesCount == 3) {
                endOfOdometer = i;
            }
        }

    }
    struct auto_t newAuto;
    int count = 0;
    for (i = 0; i < endOfMake; i++) {
        newAuto.make[count++] = line[i];
    }
    newAuto.make[count] = '\0';
    count = 0;
    for (i = endOfMake+1; i < endOfModel; i++) {
        newAuto.model[count++] = line[i];
    }
    newAuto.model[count] = '\0';
    count = 0;
    for (i = endOfModel+1; i < endOfOdometer; i++) {
        newAuto.odometerReading[count++] = line[i];
    }
    newAuto.odometerReading[count] = '\0';
    count = 0;
    for (i = endOfOdometer+1; i < sizeof(line); i++) {
        newLine[count++] = line[i];
    }
    newLine[count] = '\0';
    scan_date(newLine, &newAuto);
    return newAuto;

}
Пример #3
0
int main(void)
{
	uint32_t date;
	uint64_t real;

	printf("Scanned %d", scan_arrowy(3, 0, 0));
	_getch();
	system("CLS");
	date = scan_date();
	printf("Scanned %d/%d/%d", date_day(date), date_month(date), date_year(date));
	_getch();
	system("CLS");
	real = scan_real(18, 1);
	printf("%d,%d", real_whole(real), real_decimal(real));
	_getch();
	system("CLS");

	return 0;
}
Пример #4
0
/*
 * Set the system time
 */
int set_time(time_t *new_time)
{
#if defined(__FreeBSD__)
  struct timeval tp;
  tp.tv_sec=*new_time;
  tp.tv_usec=0;
  if (settimeofday(&tp,0)) {
#else
  if (stime(new_time)) {
#endif
    perror("Unable to set time");
    exit(1);
  }
  return 0;
}


int main(int argc, char **argv)
{
  time_t dvb_time;
  time_t real_time;
  time_t offset;

  do_print = 0;
  do_force = 0;
  do_set = 0;
  do_quiet = 0;
  ProgName = argv[0];

/*
 * Process command line arguments
 */
  do_options(argc, argv);
  if (do_quiet && do_print) {
    errmsg("quiet and print options are mutually exclusive.\n");
    exit(1);
  }
/*
 * Get the date from the currently tuned DTT multiplex
 */
  dvb_time = scan_date();
  if (dvb_time == 0) {
    errmsg("Unable to get time from multiplex.\n");
    exit(1);
  }
  time(&real_time);
  offset = dvb_time - real_time;
  if (do_print) {
    fprintf(stdout, "System time: %s", ctime(&real_time));
    fprintf(stdout, "   DTT time: %s", ctime(&dvb_time));
    fprintf(stdout, "     Offset: %ld seconds\n", offset);
  } else if (!do_quiet) {
    fprintf(stdout, "%s", ctime(&dvb_time));
  }
  if (do_set) {
    if (labs(offset) > ALLOWABLE_DELTA) {
      if (do_force) {
        set_time(&dvb_time);
      } else {
	errmsg("multiplex time differs by more than %d from system.\n", ALLOWABLE_DELTA);
	errmsg("use -f to force system clock to new time.\n");
        exit(1);
      }
    } else {
      set_time(&dvb_time);
    }
  } /* #end if (do_set) */
  return(0);
}