map/map.c

53 lines
1.2 KiB
C
Raw Normal View History

2019-12-18 15:42:32 +01:00
#include "map.h"
int main(int argc, char **argv) {
2019-12-18 17:30:34 +01:00
if (argc != 7) {
2019-12-18 15:42:32 +01:00
printf("Not enough arguments !\n");
return 1;
}
2019-12-18 17:30:34 +01:00
char *endPtr[3];
long l = strtol(argv[1], &endPtr[0], 10);
long c = strtol(argv[2], &endPtr[1], 10);
long op = strtol(argv[5], &endPtr[2], 10);
for (unsigned int i=0; i<3; i++) {
if (*endPtr[i] != '\0') {
printf("Invalid arguments !\n");
return 1;
}
2019-12-18 15:42:32 +01:00
}
2019-12-18 17:30:34 +01:00
2019-12-18 15:42:32 +01:00
char e = *argv[3], o = *argv[4], f = *argv[6];
2019-12-18 17:30:34 +01:00
char *line;
if (!(line = malloc((c+1)*sizeof(char)))) {
2019-12-18 15:42:32 +01:00
printf("Allocation fail !\n");
return 1;
}
2019-12-18 17:30:34 +01:00
line[c] = '\n';
FILE *ftpr;
ftpr = fopen("map.res", "w");
if (ftpr == NULL) {
printf("Can't open file !\n");
return 1;
2019-12-18 15:42:32 +01:00
}
2019-12-18 17:30:34 +01:00
fprintf(ftpr, "%ld%c%c%c\n", l, e, o, f);
2019-12-18 15:42:32 +01:00
srand(time(NULL));
for (unsigned int i=0; i<l; i++) {
for (unsigned int j=0; j<c; j++) {
if (rand()%100 > op) {
2019-12-18 17:30:34 +01:00
line[j] = e;
2019-12-18 15:42:32 +01:00
} else {
2019-12-18 17:30:34 +01:00
line[j] = o;
2019-12-18 15:42:32 +01:00
}
}
2019-12-18 17:30:34 +01:00
fwrite(line, sizeof(char), c+1, ftpr);
2019-12-18 15:42:32 +01:00
}
2019-12-18 17:30:34 +01:00
fclose(ftpr);
free(line);
2019-12-18 15:42:32 +01:00
return 0;
2019-12-18 17:30:34 +01:00
}