SlideShare a Scribd company logo
Ring Documentation, Release 1.2
• fwrite()
• fexists()
26.1 Read() Function
We can read the file content using the Read() function
Syntax:
Read(cFileName) ---> String contains the file content
Example:
see read("myfile.txt")
The read function can read binary files too
Example:
see read("myapp.exe")
26.2 Write() Function
We can write string to file using the Write() function
The write function can write binary data to binary files.
Syntax:
Write(cFileName,cString) # write string cString to file cFileName
Example:
# copy file
cFile = read("ring.exe")
write("ring2.exe",cFile)
26.3 Dir() Function
We can get the folder contents (files & sub folders) using the Dir() function.
Syntax:
Dir(cFolderPath) ---> List contains files & sub folders.
This function returns a list and each list item is a list of two items
• File/sub folder name
• Type (0 = File , 1 = Folder/Directory)
Example:
26.1. Read() Function 120
Ring Documentation, Release 1.2
see "Testing DIR() " + nl
mylist = dir("C:myfolder")
for x in mylist
if x[2]
see "Directory : " + x[1] + nl
else
see "File : " + x[1] + nl
ok
next
see "Files count : " + len(mylist)
26.4 Rename() Function
We can rename files using the Rename() function
Syntax:
Rename(cOldFileName,cNewFileName)
Example:
rename("file.txt","help.txt")
26.5 Remove() Function
We can delete a file using the Remove() function
Syntax:
Remove(cFileName)
Example:
remove("test.txt")
26.6 Fopen() Function
We can open a file using the Fopen() function
Syntax:
Fopen(cFileName,cMode) ---> File Handle
Mode Description
“r” Reading (The file must exist)
“w” Writing (create empty file / overwrite)
“a” Appends (create file if it doesn’t exist)
“r+” update (reading/writing)
“w+” Create empty file (reading/writing)
“a+” reading & appending
26.4. Rename() Function 121
Ring Documentation, Release 1.2
26.7 Fclose() Function
When we open a file using fopen() function, we can close it using the Fclose() function
Syntax:
Fclose(file handle)
26.8 Fflush() Function
We can flushes the output buffer of a stream using the Fflush() function
Syntax:
Fflush(file handle)
26.9 Freopen() Function
We can open another file using the same file handle and at the same file close the old file
Syntax:
Freopen(cFileName,cMode,file handle) ---> file handle
Example:
freopen("myprogoutput.txt","w+",stdout)
see "welcome" + nl
for x = 1 to 10
see x + nl
next
/*
** Read : https://en.wikipedia.org/wiki/Device_file#Device_files
** The next code is not portable, we can use iswindows() before
** using it and we can write special code for each operating system.
*/
freopen("CON","w",stdout) # For Microsoft Windows
see "Done" + nl # print to stdout again
Output:
# Output to stdout
Done
# Output to file : myprogoutput.txt
welcome
1
2
3
4
5
6
7
26.7. Fclose() Function 122
Ring Documentation, Release 1.2
8
9
10
26.10 Tempfile() Function
The function Tempfile() creates a temp. file (binary).
The file will be deleted automatically when the stream is closed
Syntax:
TempFile() ---> file handle
26.11 Tempname() Function
We can generate temp. file name using the Tempname() function
The generated name will be different from the name of any existing file
Syntax:
Tempname() ---> generated file name as string
26.12 Fseek() Function
We can set the file position of the stream using the Fseek() function
Syntax:
Fseek(file handle, nOffset, nWhence) ---> zero if successful
The next table presents the nWhence values
Value Description
0 Beginning of file
1 Current position
2 End of file
26.13 Ftell() Function
We can know the current file position of a stream using the Ftell() function
Syntax:
Ftell(file handle) ---> file position as number
26.10. Tempfile() Function 123
Ring Documentation, Release 1.2
26.14 Rewind() Function
We can set the file position to the beginning of the file using the Rewind() function
Syntax:
Rewind(file handle)
26.15 Fgetpos() Function
We can get handle to the current file position using the Fgetpos() function
Syntax:
Fgetpos(file handle) ---> position handle
26.16 Fsetpos() Function
We can set the current file position using the Fgetpos() function
Syntax:
Fsetpos(file handle,position handle)
26.17 Clearerr() Function
We can clear the EOF error and the error indicators of a stream using the clearerr() function
Syntax:
Clearerr(file handle)
26.18 Feof() Function
We can test the end-of-file indicator using the Feof() function
Syntax:
Feof(file handle) ---> returns 1 if EOF and 0 if not
26.19 Ferror() Function
We can test the error indicator of a given stream using the Ferror() function
Syntax:
Ferror(file handle) ---> returns 1 if error and 0 if not
26.14. Rewind() Function 124
Ring Documentation, Release 1.2
26.20 Perror() Function
We can print error message to the stderr using the Perror() function
Syntax:
Perror(cErrorMessage)
26.21 Fgetc() Function
We can get the next character from the stream using the Fgetc() function
Syntax:
Fgetc(file handle) ---> returns character or EOF
26.22 Fgets() Function
We can read new line from the stream using the Fgets() function
Syntax:
Fgets(file handle,nSize) ---> string
The function stop when nSize characters are read, new line character is read or EOF.
26.23 Fputc() Function
We can write a character to the stream using the Fputc() function
Syntax:
Fputc(file handle,cChar)
26.24 Fputs() Function
We can write a string to the stream using the Fputs() function
Syntax:
Fputs(file handle,cString)
26.25 Ungetc() Function
We can push a character to the stream using the Ungetc() function
The character will be available for the next read
Syntax:
26.20. Perror() Function 125
Ring Documentation, Release 1.2
Ungetc(file handle,character)
26.26 Fread() Function
We can read data from a stream using the Fread() function
Syntax:
Fread(file handle,nSize)
26.27 Fwrite() Function
We can write data to a stream using the Fwrite() function
Syntax:
Fwrite(file handle,cString)
26.28 Fexists() Function
We can check if a file exists using the Fexists() function
Syntax:
Fexists(cFileName) ---> returns 1 if the file exists
Example:
see fexists("b:mahmoudappsringring.exe") + nl +
fexists("b:mahmoudappsringring2.exe") + nl
Output:
1
0
26.29 Example
The next program test some of the file functions
See "Testing file functions" + nl
See "open file" + nl
fp = fopen("testss65.ring","r")
See "reopen" + nl
fp = freopen("testss78.ring","r",fp)
See "close file" + nl
fclose(fp)
see "temp file" + nl
26.26. Fread() Function 126
Ring Documentation, Release 1.2
fp = tempfile()
fclose(fp)
see "temp name" + nl
see tempname() + nl
remove("testsmytest1.txt")
write("teststest1.txt","hello")
rename("teststest1.txt","testsmytest2.txt")
see "print file" + nl
fp = fopen("testsfile.ring","r")
r = fgetc(fp)
while isstring(r)
see r
r = fgetc(fp)
end
fclose(fp)
see nl+"print line from the file" + nl
fp = fopen("testsfile.ring","r")
r = fgets(fp,100)
see r
fclose(fp)
fp = fopen("testsmyfile.txt","rw+")
fseek(fp,0,2) # goto end of file
fputc(fp,"t")
fputc(fp,"e")
fputc(fp,"s")
fputc(fp,"t")
fputs(fp,"test2")
fclose(fp)
see "print file" + nl
see read("testsmyfile.txt")
fp = fopen("testsmyfile.txt","r")
see "testing ungetc() " + nl
for x = 1 to 3
r = fgetc(fp)
see r + nl
ungetc(fp,r)
next
fclose(fp)
see "testing fread() " + nl
fp = fopen("ring.exe","r")
r = fread(fp,100)
see r + nl
fclose(fp)
see "testing fwrite() " + nl
fp = fopen("testsmyfile.txt","wb")
fwrite(fp,r)
fclose(fp)
26.29. Example 127
CHAPTER
TWENTYSEVEN
SYSTEM FUNCTIONS
In this chapter we are going to learn about the system functions
• System()
• SysGet()
• IsMSDOS()
• IsWindows()
• IsWindows64()
• IsUnix()
• IsMacOSX()
• IsLinux()
• IsFreeBSD()
• IsAndroid()
• Windowsnl()
• Get Command Line Arguments
• Get Active Source File Name
• CurrentDir()
• ExeFileName()
• ChDir()
• ExeFolder()
• Version()
27.1 System() Function
We can execute system commands using the system() function
Syntax:
System(cCommand)
Example:
System("myapp.exe") # Run myapp.exe
System("ls") # print list of files
128
Ring Documentation, Release 1.2
27.2 SysGet() Function
We can get environment variables using the Get() function
Syntax:
SysGet(cVariable)
Example:
see sysget("path") # print system path information
27.3 IsMSDOS() Function
We can check if the operating system is MSDOS or not using the IsMSDOS() function
Syntax:
IsMSDOS() ---> Returns 1 if the operating system is MS-DOS, Returns 0 if it's not
27.4 IsWindows() Function
We can check if the operating system is Windows or not using the IsWindows() function
Syntax:
IsWindows() ---> Returns 1 if the operating system is Windows, Returns 0 if it's not
27.5 IsWindows64() Function
We can check if the operating system is Windows 64bit or not using the IsWindows64() function
Syntax:
IsWindows64() ---> Returns 1 if the operating system is Windows64, Returns 0 if it's not
27.6 IsUnix() Function
We can check if the operating system is Unix or not using the IsUnix() function
Syntax:
IsUnix() ---> Returns 1 if the operating system is Unix, Returns 0 if it's not
27.7 IsMacOSX() Function
We can check if the operating system is Mac OS X or not using the IsMacOSX() function
Syntax:
27.2. SysGet() Function 129

More Related Content

PDF
The Ring programming language version 1.7 book - Part 29 of 196
PDF
The Ring programming language version 1.5.1 book - Part 24 of 180
PDF
The Ring programming language version 1.5.2 book - Part 25 of 181
PDF
The Ring programming language version 1.10 book - Part 34 of 212
PDF
The Ring programming language version 1.3 book - Part 17 of 88
PDF
The Ring programming language version 1.6 book - Part 28 of 189
PDF
The Ring programming language version 1.4.1 book - Part 7 of 31
PDF
The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 29 of 196
The Ring programming language version 1.5.1 book - Part 24 of 180
The Ring programming language version 1.5.2 book - Part 25 of 181
The Ring programming language version 1.10 book - Part 34 of 212
The Ring programming language version 1.3 book - Part 17 of 88
The Ring programming language version 1.6 book - Part 28 of 189
The Ring programming language version 1.4.1 book - Part 7 of 31
The Ring programming language version 1.7 book - Part 30 of 196

What's hot (19)

PDF
The Ring programming language version 1.5.3 book - Part 26 of 184
PDF
The Ring programming language version 1.5.3 book - Part 25 of 184
PDF
The Ring programming language version 1.10 book - Part 35 of 212
PPT
Come on, PHP 5.4!
DOC
Inheritance
PDF
Top 10 Random Linux/Ubuntu Commands
ODP
Linux commd
ODP
Linux commd
PPTX
Linux comands for Hadoop
PDF
The Ring programming language version 1.5.2 book - Part 26 of 181
PPT
Anandha ganesh linux1.ppt
PPTX
Data File Handiling File POINTERS IN C++
PDF
Termux commands-list
PDF
C++ course start
PPTX
Linux Commands
DOC
Unix Basics For Testers
DOCX
40 basic linux command
PDF
Looking Ahead to Tcl 8.6
PDF
C++ prgms io file unit 7
The Ring programming language version 1.5.3 book - Part 26 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.10 book - Part 35 of 212
Come on, PHP 5.4!
Inheritance
Top 10 Random Linux/Ubuntu Commands
Linux commd
Linux commd
Linux comands for Hadoop
The Ring programming language version 1.5.2 book - Part 26 of 181
Anandha ganesh linux1.ppt
Data File Handiling File POINTERS IN C++
Termux commands-list
C++ course start
Linux Commands
Unix Basics For Testers
40 basic linux command
Looking Ahead to Tcl 8.6
C++ prgms io file unit 7
Ad

Viewers also liked (20)

PDF
The Ring programming language version 1.2 book - Part 32 of 84
PDF
The Ring programming language version 1.2 book - Part 28 of 84
PDF
The Ring programming language version 1.2 book - Part 17 of 84
PDF
The Ring programming language version 1.2 book - Part 34 of 84
PDF
The Ring programming language version 1.2 book - Part 33 of 84
PDF
The Ring programming language version 1.2 book - Part 37 of 84
PDF
The Ring programming language version 1.2 book - Part 18 of 84
PDF
The Ring programming language version 1.2 book - Part 1 of 84
PDF
The Ring programming language version 1.2 book - Part 20 of 84
PDF
The Ring programming language version 1.2 book - Part 16 of 84
PDF
The Ring programming language version 1.2 book - Part 19 of 84
PDF
Variables Python
PDF
Foro Nacional de jóvenes 2017 | Scouts Ecuador
PPTX
2017.2.17 末梢からの血管作動薬投与の安全性について
PPTX
Corporate Training Webinar: Primer to Skill based learning – 5 ways to identi...
PDF
How to make font transparent in PowerPoint
PDF
The Ring programming language version 1.2 book - Part 14 of 84
PDF
The Ring programming language version 1.2 book - Part 27 of 84
PDF
The Ring programming language version 1.2 book - Part 36 of 84
PDF
The Ring programming language version 1.2 book - Part 13 of 84
The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 28 of 84
The Ring programming language version 1.2 book - Part 17 of 84
The Ring programming language version 1.2 book - Part 34 of 84
The Ring programming language version 1.2 book - Part 33 of 84
The Ring programming language version 1.2 book - Part 37 of 84
The Ring programming language version 1.2 book - Part 18 of 84
The Ring programming language version 1.2 book - Part 1 of 84
The Ring programming language version 1.2 book - Part 20 of 84
The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 19 of 84
Variables Python
Foro Nacional de jóvenes 2017 | Scouts Ecuador
2017.2.17 末梢からの血管作動薬投与の安全性について
Corporate Training Webinar: Primer to Skill based learning – 5 ways to identi...
How to make font transparent in PowerPoint
The Ring programming language version 1.2 book - Part 14 of 84
The Ring programming language version 1.2 book - Part 27 of 84
The Ring programming language version 1.2 book - Part 36 of 84
The Ring programming language version 1.2 book - Part 13 of 84
Ad

Similar to The Ring programming language version 1.2 book - Part 15 of 84 (20)

PDF
The Ring programming language version 1.8 book - Part 31 of 202
PDF
The Ring programming language version 1.5.4 book - Part 26 of 185
PDF
The Ring programming language version 1.9 book - Part 33 of 210
PPTX
C Programming Unit-5
PDF
ppt5-190810161800 (1).pdf
PPTX
Built in function
PPS
C programming session 08
PDF
File Handling in C Programming
PPTX
Systemcall1
PPTX
File management
PDF
The Ring programming language version 1.5.1 book - Part 25 of 180
DOC
Unit v
PPT
cpp-file-handling
PPT
Cpp file-handling
PPTX
File Handling in C
PPTX
Introduction to files management systems
PPTX
Managing console i/o operation,working with files
PPTX
Managing,working with files
PPTX
pre processor and file handling in c language ppt
PDF
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
The Ring programming language version 1.8 book - Part 31 of 202
The Ring programming language version 1.5.4 book - Part 26 of 185
The Ring programming language version 1.9 book - Part 33 of 210
C Programming Unit-5
ppt5-190810161800 (1).pdf
Built in function
C programming session 08
File Handling in C Programming
Systemcall1
File management
The Ring programming language version 1.5.1 book - Part 25 of 180
Unit v
cpp-file-handling
Cpp file-handling
File Handling in C
Introduction to files management systems
Managing console i/o operation,working with files
Managing,working with files
pre processor and file handling in c language ppt
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf

More from Mahmoud Samir Fayed (20)

PDF
The Ring programming language version 1.10 book - Part 212 of 212
PDF
The Ring programming language version 1.10 book - Part 211 of 212
PDF
The Ring programming language version 1.10 book - Part 210 of 212
PDF
The Ring programming language version 1.10 book - Part 208 of 212
PDF
The Ring programming language version 1.10 book - Part 207 of 212
PDF
The Ring programming language version 1.10 book - Part 205 of 212
PDF
The Ring programming language version 1.10 book - Part 206 of 212
PDF
The Ring programming language version 1.10 book - Part 204 of 212
PDF
The Ring programming language version 1.10 book - Part 203 of 212
PDF
The Ring programming language version 1.10 book - Part 202 of 212
PDF
The Ring programming language version 1.10 book - Part 201 of 212
PDF
The Ring programming language version 1.10 book - Part 200 of 212
PDF
The Ring programming language version 1.10 book - Part 199 of 212
PDF
The Ring programming language version 1.10 book - Part 198 of 212
PDF
The Ring programming language version 1.10 book - Part 197 of 212
PDF
The Ring programming language version 1.10 book - Part 196 of 212
PDF
The Ring programming language version 1.10 book - Part 195 of 212
PDF
The Ring programming language version 1.10 book - Part 194 of 212
PDF
The Ring programming language version 1.10 book - Part 193 of 212
PDF
The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 192 of 212

Recently uploaded (20)

PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
history of c programming in notes for students .pptx
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
medical staffing services at VALiNTRY
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
AI in Product Development-omnex systems
PPTX
ai tools demonstartion for schools and inter college
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
System and Network Administration Chapter 2
Softaken Excel to vCard Converter Software.pdf
Understanding Forklifts - TECH EHS Solution
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Internet Downloader Manager (IDM) Crack 6.42 Build 41
VVF-Customer-Presentation2025-Ver1.9.pptx
history of c programming in notes for students .pptx
How to Migrate SBCGlobal Email to Yahoo Easily
Odoo Companies in India – Driving Business Transformation.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
medical staffing services at VALiNTRY
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
L1 - Introduction to python Backend.pptx
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Design an Analysis of Algorithms II-SECS-1021-03
AI in Product Development-omnex systems
ai tools demonstartion for schools and inter college
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
System and Network Administration Chapter 2

The Ring programming language version 1.2 book - Part 15 of 84

  • 1. Ring Documentation, Release 1.2 • fwrite() • fexists() 26.1 Read() Function We can read the file content using the Read() function Syntax: Read(cFileName) ---> String contains the file content Example: see read("myfile.txt") The read function can read binary files too Example: see read("myapp.exe") 26.2 Write() Function We can write string to file using the Write() function The write function can write binary data to binary files. Syntax: Write(cFileName,cString) # write string cString to file cFileName Example: # copy file cFile = read("ring.exe") write("ring2.exe",cFile) 26.3 Dir() Function We can get the folder contents (files & sub folders) using the Dir() function. Syntax: Dir(cFolderPath) ---> List contains files & sub folders. This function returns a list and each list item is a list of two items • File/sub folder name • Type (0 = File , 1 = Folder/Directory) Example: 26.1. Read() Function 120
  • 2. Ring Documentation, Release 1.2 see "Testing DIR() " + nl mylist = dir("C:myfolder") for x in mylist if x[2] see "Directory : " + x[1] + nl else see "File : " + x[1] + nl ok next see "Files count : " + len(mylist) 26.4 Rename() Function We can rename files using the Rename() function Syntax: Rename(cOldFileName,cNewFileName) Example: rename("file.txt","help.txt") 26.5 Remove() Function We can delete a file using the Remove() function Syntax: Remove(cFileName) Example: remove("test.txt") 26.6 Fopen() Function We can open a file using the Fopen() function Syntax: Fopen(cFileName,cMode) ---> File Handle Mode Description “r” Reading (The file must exist) “w” Writing (create empty file / overwrite) “a” Appends (create file if it doesn’t exist) “r+” update (reading/writing) “w+” Create empty file (reading/writing) “a+” reading & appending 26.4. Rename() Function 121
  • 3. Ring Documentation, Release 1.2 26.7 Fclose() Function When we open a file using fopen() function, we can close it using the Fclose() function Syntax: Fclose(file handle) 26.8 Fflush() Function We can flushes the output buffer of a stream using the Fflush() function Syntax: Fflush(file handle) 26.9 Freopen() Function We can open another file using the same file handle and at the same file close the old file Syntax: Freopen(cFileName,cMode,file handle) ---> file handle Example: freopen("myprogoutput.txt","w+",stdout) see "welcome" + nl for x = 1 to 10 see x + nl next /* ** Read : https://en.wikipedia.org/wiki/Device_file#Device_files ** The next code is not portable, we can use iswindows() before ** using it and we can write special code for each operating system. */ freopen("CON","w",stdout) # For Microsoft Windows see "Done" + nl # print to stdout again Output: # Output to stdout Done # Output to file : myprogoutput.txt welcome 1 2 3 4 5 6 7 26.7. Fclose() Function 122
  • 4. Ring Documentation, Release 1.2 8 9 10 26.10 Tempfile() Function The function Tempfile() creates a temp. file (binary). The file will be deleted automatically when the stream is closed Syntax: TempFile() ---> file handle 26.11 Tempname() Function We can generate temp. file name using the Tempname() function The generated name will be different from the name of any existing file Syntax: Tempname() ---> generated file name as string 26.12 Fseek() Function We can set the file position of the stream using the Fseek() function Syntax: Fseek(file handle, nOffset, nWhence) ---> zero if successful The next table presents the nWhence values Value Description 0 Beginning of file 1 Current position 2 End of file 26.13 Ftell() Function We can know the current file position of a stream using the Ftell() function Syntax: Ftell(file handle) ---> file position as number 26.10. Tempfile() Function 123
  • 5. Ring Documentation, Release 1.2 26.14 Rewind() Function We can set the file position to the beginning of the file using the Rewind() function Syntax: Rewind(file handle) 26.15 Fgetpos() Function We can get handle to the current file position using the Fgetpos() function Syntax: Fgetpos(file handle) ---> position handle 26.16 Fsetpos() Function We can set the current file position using the Fgetpos() function Syntax: Fsetpos(file handle,position handle) 26.17 Clearerr() Function We can clear the EOF error and the error indicators of a stream using the clearerr() function Syntax: Clearerr(file handle) 26.18 Feof() Function We can test the end-of-file indicator using the Feof() function Syntax: Feof(file handle) ---> returns 1 if EOF and 0 if not 26.19 Ferror() Function We can test the error indicator of a given stream using the Ferror() function Syntax: Ferror(file handle) ---> returns 1 if error and 0 if not 26.14. Rewind() Function 124
  • 6. Ring Documentation, Release 1.2 26.20 Perror() Function We can print error message to the stderr using the Perror() function Syntax: Perror(cErrorMessage) 26.21 Fgetc() Function We can get the next character from the stream using the Fgetc() function Syntax: Fgetc(file handle) ---> returns character or EOF 26.22 Fgets() Function We can read new line from the stream using the Fgets() function Syntax: Fgets(file handle,nSize) ---> string The function stop when nSize characters are read, new line character is read or EOF. 26.23 Fputc() Function We can write a character to the stream using the Fputc() function Syntax: Fputc(file handle,cChar) 26.24 Fputs() Function We can write a string to the stream using the Fputs() function Syntax: Fputs(file handle,cString) 26.25 Ungetc() Function We can push a character to the stream using the Ungetc() function The character will be available for the next read Syntax: 26.20. Perror() Function 125
  • 7. Ring Documentation, Release 1.2 Ungetc(file handle,character) 26.26 Fread() Function We can read data from a stream using the Fread() function Syntax: Fread(file handle,nSize) 26.27 Fwrite() Function We can write data to a stream using the Fwrite() function Syntax: Fwrite(file handle,cString) 26.28 Fexists() Function We can check if a file exists using the Fexists() function Syntax: Fexists(cFileName) ---> returns 1 if the file exists Example: see fexists("b:mahmoudappsringring.exe") + nl + fexists("b:mahmoudappsringring2.exe") + nl Output: 1 0 26.29 Example The next program test some of the file functions See "Testing file functions" + nl See "open file" + nl fp = fopen("testss65.ring","r") See "reopen" + nl fp = freopen("testss78.ring","r",fp) See "close file" + nl fclose(fp) see "temp file" + nl 26.26. Fread() Function 126
  • 8. Ring Documentation, Release 1.2 fp = tempfile() fclose(fp) see "temp name" + nl see tempname() + nl remove("testsmytest1.txt") write("teststest1.txt","hello") rename("teststest1.txt","testsmytest2.txt") see "print file" + nl fp = fopen("testsfile.ring","r") r = fgetc(fp) while isstring(r) see r r = fgetc(fp) end fclose(fp) see nl+"print line from the file" + nl fp = fopen("testsfile.ring","r") r = fgets(fp,100) see r fclose(fp) fp = fopen("testsmyfile.txt","rw+") fseek(fp,0,2) # goto end of file fputc(fp,"t") fputc(fp,"e") fputc(fp,"s") fputc(fp,"t") fputs(fp,"test2") fclose(fp) see "print file" + nl see read("testsmyfile.txt") fp = fopen("testsmyfile.txt","r") see "testing ungetc() " + nl for x = 1 to 3 r = fgetc(fp) see r + nl ungetc(fp,r) next fclose(fp) see "testing fread() " + nl fp = fopen("ring.exe","r") r = fread(fp,100) see r + nl fclose(fp) see "testing fwrite() " + nl fp = fopen("testsmyfile.txt","wb") fwrite(fp,r) fclose(fp) 26.29. Example 127
  • 9. CHAPTER TWENTYSEVEN SYSTEM FUNCTIONS In this chapter we are going to learn about the system functions • System() • SysGet() • IsMSDOS() • IsWindows() • IsWindows64() • IsUnix() • IsMacOSX() • IsLinux() • IsFreeBSD() • IsAndroid() • Windowsnl() • Get Command Line Arguments • Get Active Source File Name • CurrentDir() • ExeFileName() • ChDir() • ExeFolder() • Version() 27.1 System() Function We can execute system commands using the system() function Syntax: System(cCommand) Example: System("myapp.exe") # Run myapp.exe System("ls") # print list of files 128
  • 10. Ring Documentation, Release 1.2 27.2 SysGet() Function We can get environment variables using the Get() function Syntax: SysGet(cVariable) Example: see sysget("path") # print system path information 27.3 IsMSDOS() Function We can check if the operating system is MSDOS or not using the IsMSDOS() function Syntax: IsMSDOS() ---> Returns 1 if the operating system is MS-DOS, Returns 0 if it's not 27.4 IsWindows() Function We can check if the operating system is Windows or not using the IsWindows() function Syntax: IsWindows() ---> Returns 1 if the operating system is Windows, Returns 0 if it's not 27.5 IsWindows64() Function We can check if the operating system is Windows 64bit or not using the IsWindows64() function Syntax: IsWindows64() ---> Returns 1 if the operating system is Windows64, Returns 0 if it's not 27.6 IsUnix() Function We can check if the operating system is Unix or not using the IsUnix() function Syntax: IsUnix() ---> Returns 1 if the operating system is Unix, Returns 0 if it's not 27.7 IsMacOSX() Function We can check if the operating system is Mac OS X or not using the IsMacOSX() function Syntax: 27.2. SysGet() Function 129