pointers - Read data into a float array in C -


I am creating a program where I need to load some temporary point data of the file from the file 103.45 < 123.45
456.67



I was wondering how to store these data directly in the array of floating point numbers using Fried () Go. I think it is not difficult to use pointers, but I am not so good with them. Anyone can tell me that

to read the data from the file fgets () and sscanf () .

  / * Verification and error checking * / fgets (buf, sizeof buf, fp) is required; Sscanf (buf, "% f", and tmp);  

To manage the number of float, you have two options.

  1. Use an array of fixed size
  2. molok () , for a better array and friends

  / * 1. Use an array of fixed size * / float array [1000];  

  / * 2. Use `malloc ()`, `realloc ()` and friends for a growable array * / float * array; Array = maulock (1000 * size * array); / * ... Start to read the floats ... loop ... * (/ if array_needs_to_grow) {float * tmp = realloc (array, new_size); If (tmp == null) / * oops, error: no memory * /; Array = tmp; } / * End read loop * / / * ... use array ... * / free (array);  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -