Hello,
I have some trouble with my homework and I can't find the problem.
my code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "input3.h"
int main(int argc, char **argv) {
if (argc < 3) {
printf("Aufruf: %s <anzahl> <bundesland>\n", argv[0]);
printf("Beispiel: %s 100 Bayern\n", argv[0]);
printf("Klein-/Großschreibung beachten!\n");
exit(1);
}
int anzahl = atoi(argv[1]);
char *bundesland = argv[2];
char staedte[MAX_LAENGE_ARR][MAX_LAENGE_STR];
char laender[MAX_LAENGE_ARR][MAX_LAENGE_STR];
int bewohner[MAX_LAENGE_ARR];
int len = read_file("staedte.csv", staedte, laender, bewohner);
char *result[len];
int j, i=0;
int diff = 1;
int min =1;
for (j=0; j<len; j++) {
result[j] = (char*) malloc(100*sizeof(char));
diff = strcmp(bundesland, laender[j]);
min = bewohner[j] - anzahl;
if (diff ==0 && 0 <= min) {
snprintf(result[i], 100, "Die Stadt %s hat %d Einwohner.", staedte[j], bewohner[j]);
i++;
}
}
write_file(result, len);
free(*result);
}
you open the code with ./<program name> <number> <country> and it pastes on a .txt file every city of the country + its population but only those whose population is higher than the entered number.
My problem is that there are multiple empty lines and I don't know what to do.