IHYPRESS.NET
C
HOME | ASP | C | CSS | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
COne Dimensional Arrays ❯ Partially Filled Arrays
<07.06>
/* Problem: This program partially fills an array from a file until the end of file (EOF). We get the actual number of data read */ #include <stdio.h> #define SIZE 100 /* size of the array */ int array_from_file (double a[], int size) { int i; FILE* in; in = fopen ("data_array.dat", "r"); i=0; /* the first cell */ /* filling the array cell by cell */ /* until it is full or until the EOF */ while (i < SIZE && fscanf (in, "%lf", &a[i]) != EOF) { i=i+1; } fclose (in); /* the actual number of values in the array */ return (i); } int main (void) { double array[SIZE]; int actual_size, i; actual_size = array_from_file (array, SIZE); for (i=0; i < actual_size; ++i) printf ("%3.1lf ", array[i]); printf ("\nThe array contains %d values ", actual_size); printf ("for a capacity of %d cells.\n", SIZE); return (0); }
Hergestellt in Deutschland / Made in Germany
43.3 56.1 23.4 87.5 123.2 13.4 77.1 The array contains 7 values for a capacity of 100 cells.
COPYRIGHT © 2015-2024 IHYPRESS.NET. A DIVISION OF IHY PRESS. ALL RIGHTS RESERVED.