Guest User

Untitled

a guest
Dec 16th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <assert.h>
  4.  
  5. void luetaan(double **x, double **y, int *pituus);
  6.  
  7. int main (void) {
  8. double *x, *y;
  9. int *pituus, i;
  10.  
  11. luetaan(&x, &y, pituus);
  12.  
  13. printf("%d\n", &pituus);
  14.  
  15. for (i = 0; i < *pituus; i++) {
  16. printf("%lf %lf \n", x[i], y[i]);
  17. }
  18.  
  19. return 0;
  20. }
  21.  
  22. void luetaan(double **x, double **y, int *pituus) {
  23. char s[1024];
  24. int i;
  25.  
  26. // Luettava tiedosto.
  27.  
  28. FILE *tiedosto;
  29. tiedosto = fopen("data1.txt", "r");
  30.  
  31. // Lasketaan tiedoston rivien lukumäärä muuttujaan pituus.
  32.  
  33. pituus = 0;
  34.  
  35. while (!feof(tiedosto)) {
  36. fgets(s, 1024, tiedosto);
  37. pituus++;
  38. }
  39.  
  40. rewind(tiedosto);
  41.  
  42. *x = (double *) malloc(sizeof(double)*(*pituus));
  43. *y = (double *) malloc(sizeof(double)*(*pituus));
  44.  
  45. // Luetaan data
  46.  
  47.  
  48. for (i = 0; i < *pituus; i++) {
  49. fscanf(tiedosto,"%lf %lf", &x[i], &y[i]);
  50. }
  51.  
  52. fclose(tiedosto);
  53. }
Add Comment
Please, Sign In to add comment