Skip to content
Snippets Groups Projects
Commit 7c308f20 authored by Boris Stefanovic's avatar Boris Stefanovic
Browse files

save

parent 27987d1a
Branches
Tags
No related merge requests found
#define _GNU_SOURCE
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "common.h"
#include "vector.h"
void help(const char* callname) {
fprintf(stderr, "\nUSAGE: %s <INPUT_FILE> <OUTPUT_FILE>\n", callname);
}
int_t read_int(FILE* file) {
char* line;
size_t len;
char* rest;
getline(&line, &len, file);
return strtol(line, &rest, 10);
}
bool read_vector_int(FILE* file, vector_int_t* vector) {
char* line;
size_t len;
char* rest;
for (size_t i = 0; i < vector->dim; ++i) {
getline(&line, &len, file);
vector->data[i] = strtol(line, &rest, 10);
}
}
int main(int argc, char** argv) {
fprintf(stderr, "USAGE: %s <INPUT_FILE> <OUTPUT_FILE>\n", argv[0]);
char* ipath = "/dev/stdin";
char* opath = "/dev/stdout";
if (argc > 1) ipath = argv[1];
if (argc <= 1) help(argv[0]);
char* ipath = NULL;
char* opath = NULL;
if (argc > 1) {
ipath = argv[1];
if (access(ipath, F_OK) == -1) {
fprintf(stderr, "IFILE: [ %s ] file does not exist !", ipath);
return EXIT_FAILURE;
}
}
if (argc > 2) opath = argv[2];
// READ
FILE* ifile = ipath != NULL ? fopen(ipath, "r") : stdin;
const size_t dim = read_int(ifile);
const int_t nclusters = read_int(ifile);
int_t next;
while ()
fscanf(ifile, "%ld", &next);
// WRITE
FILE* ofile = opath != NULL ? fopen(opath, "w") : stdout;
// TODO
return EXIT_SUCCESS;
}
......@@ -8,7 +8,8 @@
vector_int_t* vector_int_create(const size_t dim, const int_t* data) {
vector_int_t* v;
if ((v = malloc(dim * sizeof(int))) == NULL) return NULL;
//if ((v = malloc(dim * sizeof(int))) == NULL) return NULL;
if ((v = calloc(dim, sizeof(int))) == NULL) return NULL;
v->dim = dim;
for (size_t i = 0; i < dim; ++i) v->data[i] = data[i];
return v;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment