Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <assert.h>
- void luetaan(double **x, double **y, int *pituus);
- int main (void) {
- double *x, *y;
- int *pituus, i;
- luetaan(&x, &y, pituus);
- printf("%d\n", &pituus);
- for (i = 0; i < *pituus; i++) {
- printf("%lf %lf \n", x[i], y[i]);
- }
- return 0;
- }
- void luetaan(double **x, double **y, int *pituus) {
- char s[1024];
- int i;
- // Luettava tiedosto.
- FILE *tiedosto;
- tiedosto = fopen("data1.txt", "r");
- // Lasketaan tiedoston rivien lukumäärä muuttujaan pituus.
- pituus = 0;
- while (!feof(tiedosto)) {
- fgets(s, 1024, tiedosto);
- pituus++;
- }
- rewind(tiedosto);
- *x = (double *) malloc(sizeof(double)*(*pituus));
- *y = (double *) malloc(sizeof(double)*(*pituus));
- // Luetaan data
- for (i = 0; i < *pituus; i++) {
- fscanf(tiedosto,"%lf %lf", &x[i], &y[i]);
- }
- fclose(tiedosto);
- }
Add Comment
Please, Sign In to add comment