Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* This Program generates a file with a pseudo-random number of st_record_t structures. The file is passed by command line arguments. The program must by executed, in UNIX, this way: ./file_gen -path <path> */
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <string.h>
- #include "types.h"
- #define MSG_INVALID_INPUT "Your input was not valid"
- #define CMD_FLAG_PATH_POSITION 1
- #define CMD_ARG_PATH_POSITION 2
- #define CMD_FLAG_PATH "-path"
- #define SDM_MAX 10000.0
- status_t validate_arguments (int argc, char * argv []);
- int main (int argc, char * argv [])
- {
- FILE * fi;
- size_t i;
- st_record_t aux_struct, aux2_struct;
- int size;
- if ((validate_arguments(argc, argv))!= OK)
- {
- fprintf(stderr, "%sn", MSG_INVALID_INPUT);
- return EXIT_FAILURE;
- }
- if((fi = fopen(argv[CMD_ARG_PATH_POSITION], "wb")) == NULL)
- return EXIT_FAILURE;
- srand(time(NULL));
- for (i=0; i<(size=100); i++)
- {
- aux_struct.SDM = (((float)rand()/(float)(RAND_MAX)) * SDM_MAX); /*pseudo-random real number between 0 and SDM_MAX*/
- (aux_struct.ID) = i;
- (aux_struct.coordinates)->latitude.deg = rand()%180;
- (aux_struct.coordinates)->latitude.min = rand()%60;
- (aux_struct.coordinates)->latitude.sec = rand()%60;
- (aux_struct.coordinates)->longitude.deg = rand()%180;
- (aux_struct.coordinates)->longitude.min = rand()%60;
- (aux_struct.coordinates)->longitude.sec = rand()%60;
- if((fwrite (&aux_struct, sizeof(st_record_t), 1, fi))!=1)
- return ERROR_WRITING_FILE;
- }
- if(fclose(fi) == EOF)
- return EXIT_FAILURE
- return EXIT_SUCCESS;
- }
- typedef struct {
- unsigned char deg, min, sec;
- }angle_t;
- typedef struct {
- angle_t latitude, longitude;
- }st_coord_t;
- typedef struct {
- float SDM;
- size_t ID;
- st_coord_t * coordinates;
- }st_record_t;
- aux_struct.coordinates = malloc(sizeof(st_coord_t));
- typedef struct {
- float SDM;
- size_t ID;
- st_coord_t * coordinates;
- }st_record_t;
- aux_struct.coordinates=malloc(sizeof(st_coord_t));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement