Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. int main(int argc, char **argv) {
  2. if (argc < 3) {
  3. printf("Aufruf: %s <anzahl> <bundesland>n", argv[0]);
  4. printf("Beispiel: %s 100 Bayernn", argv[0]);
  5. printf("Klein-/Großschreibung beachten!n");
  6. exit(1);
  7. }
  8. int anzahl = atoi(argv[1]);
  9. char *bundesland = argv[2];
  10.  
  11. // Statisch allokierter Speicher
  12. char staedte[MAX_LAENGE_ARR][MAX_LAENGE_STR];
  13. char laender[MAX_LAENGE_ARR][MAX_LAENGE_STR];
  14. int bewohner[MAX_LAENGE_ARR];
  15.  
  16. int len = read_file("staedte.csv", staedte, laender, bewohner);
  17.  
  18. // Hier implementieren
  19. int x=0;
  20. int d=0;
  21. //int b=0;
  22. //char* zeile_array=(char*) malloc (len * sizeof(char));
  23. char *zeile_array[50];
  24. char *zeile;
  25. zeile=(char*) malloc(100); //allocating memory
  26. for(x=0;x<len;x++)
  27. {
  28. if(strcmp(laender[x],bundesland) == 0 && bewohner[x] >= anzahl)
  29. {
  30. sprintf(zeile, "Die Stadt %p hat %d Einwohner.",staedte[x],bewohner[x]);
  31. zeile_array[d]=zeile; // putting it into array
  32. d=d+1;
  33. }
  34. }
  35. //b++;
  36. }
  37. write_file(zeile_array,d);
  38. free(zeile);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement