Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Example:
rename("file.txt","help.txt")
Example:
remove("test.txt")
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
When we open a file using fopen() function, we can close it using the Fclose() function
Syntax:
Fclose(file handle)
We can flushes the output buffer of a stream using the Fflush() function
Syntax:
Fflush(file handle)
We can open another file using the same file handle and at the same time 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.
*/
Output:
# Output to stdout
Done
8
9
10
We can set the file position of the stream using the Fseek() function
Syntax:
Fseek(file handle, nOffset, nWhence) ---> zero if successful
We can know the current file position of a stream using the Ftell() function
Syntax:
Ftell(file handle) ---> file position as number
We can set the file position to the beginning of the file using the Rewind() function
Syntax:
Rewind(file handle)
We can get handle to the current file position using the Fgetpos() function
Syntax:
Fgetpos(file handle) ---> position handle
We can set the current file position using the Fgetpos() function
Syntax:
Fsetpos(file handle,position handle)
We can clear the EOF error and the error indicators of a stream using the clearerr() function
Syntax:
Clearerr(file handle)
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
We can print error message to the stderr using the Perror() function
Syntax:
Perror(cErrorMessage)
We can get the next character from the stream using the Fgetc() function
Syntax:
Fgetc(file handle) ---> returns character or EOF
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.
Ungetc(file handle,character)
Example:
see fexists("b:\mahmoud\apps\ring\ring.exe") + nl +
fexists("b:\mahmoud\apps\ring\ring2.exe") + nl
Output:
1
0
33.29 Example
See "reopen" + nl
fp = freopen(exefolder() + "../tests/scripts/s78.ring","r",fp)
See "close file" + nl
fclose(fp)
fp = tempfile()
fclose(fp)
remove(exefolder() + "../tests/scripts/mytest2.txt")
write(exefolder() + "../tests/scripts/tests1.txt","hello")
rename(exefolder() + "../tests/scripts/test1.txt",exefolder() +
"../tests/scripts/mytests2.txt")
fp = fopen(exefolder() + "../tests/scripts/test78.txt","r")
see "testing ungetc() " + nl
for x = 1 to 3
r = fgetc(fp)
see r + nl
ungetc(fp,r)
next
fclose(fp)
THIRTYFOUR
SYSTEM FUNCTIONS
Example:
260
Ring Documentation, Release 1.7
Example:
see sysget("path") # print system path information
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
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
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
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