Find Current Position in File
When you open a file, MATLAB® creates a pointer to indicate the current position within the file. Open the following
badpoem.txt file and perform a read operation (which advances the position pointer). Then, query the final position in the file after the read operation.
fopen to open the file. Then, use
ftell to query the current position.
fid = fopen('badpoem.txt');
ans = 0
fgetl, read the first line and examine the current position after the read operation.
tline1 = fgetl(fid) % read the first line
tline1 = 'Oranges and lemons,'
ans = 20
Read the second line and examine the current position.
tline2 = fgetl(fid) % read the second line
tline2 = 'Pineapples and tea.'
ans = 40
Close the file.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
When the MATLAB® behavior differs from the C compiler behavior, the generated code
usually matches the C compiler behavior. For example, if you use
fseek to seek past the end of a file, the behavior of
ftell in the generated code matches the C compiler
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version HistoryIntroduced before R2006a
R2022b: Use function in thread-based environments
This function supports thread-based environments.