SourcePoint AMD Help

Table of Contents

fgets

Read a string from a file.

Syntax

[result =] fgets(string, file_handle)

Where:

result

specifies an nstring variable to which the function return value is assigned. If result is not specified, the return value is displayed on the next line of the screen.

string

is an nstring variable to receive the string read.

file_handle

is a file handle returned from a previous fopen command.

Discussion

The fgets function reads a string from a file previously opened by fopen. The string is stored in the first argument specified and is also the return value of the function. ย Multiple fgets commands will get consecutive, new line-delimited strings. ย Strings longer than 1024 characters are truncated. ย Fgets returns an empty string on end of file. The feof function can also be used to detect end of file.

Example

Command input:

define ord4 file1
file1 = fopen("test.dat", "w")
fputs("this is a test", file1)
fclose(file1)
define nstring buf
file1 = fopen("test.dat", "r")
fgets(buf, file1)

Result:

"this is a test"

Related Topics: