FileToArray
- Updated2023-02-21
- 3 minute(s) read
FileToArray
int FileToArray (char fileName[], void *array, int dataType, size_t numberOfElements, size_t numberOfGroups, int arrayDataOrder, int fileLayout, int fileType);
Purpose
Reads data from a file into an array. You can use FileToArray with files you create using ArrayToFile. FileToArray opens, reads, and closes the file.
![]() |
Note This function cannot convert NaN and Inf in ASCII files to double-precision numbers. This function can convert these special double-precision numbers in binary files. If your data contains these special double-precision numbers, National Instruments recommends using files in binary format with this function. |
Parameters
Input | ||||||||||||||||||||||||||||||||
Name | Type | Description | ||||||||||||||||||||||||||||||
fileName | char [] | Name of the file to read. fileName can be an absolute pathname or a relative filename. If you use a relative filename, FileToArray locates the file relative to the current working directory. |
||||||||||||||||||||||||||||||
dataType | int | Data type of the array. The data in the file should match this data type. dataType must be one of the following data types:
|
||||||||||||||||||||||||||||||
numberOfElements | size_t | Number of data points to read from the file. | ||||||||||||||||||||||||||||||
numberOfGroups | size_t | If the file is in ASCII format, numberOfGroups specifies the number of groups into which the data in the file is divided. FileToArray can read groups as columns or rows. If you do not want to read your data as groups, use 1. | ||||||||||||||||||||||||||||||
arrayDataOrder | int | If you divide your data into groups, arrayDataOrder specifies how to store the data from different groups in the array. The choices are as follows:
|
||||||||||||||||||||||||||||||
fileLayout | int | If the file is in ASCII format, fileLayout specifies how the data is arranged in the file. The choices are as follows:
|
||||||||||||||||||||||||||||||
fileType | int | Specifies whether the file is in ASCII or binary format. The choices are as follows:
|
||||||||||||||||||||||||||||||
Output | ||||||||||||||||||||||||||||||||
Name | Type | Description | ||||||||||||||||||||||||||||||
array | void * | Numeric array in which to store the data read from the file. |
Return Value
Name | Type | Description | ||||||||||||||||||||||
status | int | Indicates whether the function succeeded or failed. If the value is –1, –2, or –3, you can use GetFmtIOError to get more information about the type of error that occurred.
|
Additional Information
Library: Formatting and I/O Library
Include file: formatio.h
LabWindows/CVI compatibility: LabWindows/CVI 4.0 and later
Example
Refer to fileio\arrayfile.cws for an example of using the FileToArray function.