Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How does C language store the values in an array in a text file?
How does C language store the values in an array in a text file?
There are two ways to write array type a[N] to a file.

1 Write an array to a file in binary form. such as

fwrite(a,sizeof(a), 1,FP);

You can write the entire array in binary form to a file.

2 according to the elements, write files in turn. The specific writing format is related to the type of array. If it is an int array, you can write:

int I;

for(I = 0; I & ltn;; i++)

fprintf("%d ",a[I]);

These two methods have their own advantages and disadvantages:

As far as the code amount of 1 is concerned, the first method is simpler and more efficient;

2. In terms of operational efficiency, the first method is more efficient;

3 file space size:

If there are many string elements in the array, the target file size is similar after writing, or the second method takes up less space.

If there are more integer or floating-point data in the array, the first method takes up less space.

4 target file readability:

The file obtained by the first method is a binary file, which needs to be opened by a special reader, and only professionals can read it.

The second method is more intuitive, and the output results can be read by directly opening the text file.