GETC function

Purpose:

GETC returns the ASCII code value of a character from the input of the file in the hFile parameter and increments the file pointer to point to the next character in the file.

Syntax:

RetVal = GETC(hFile AS FILE)

Return Value:

  • Data type: INTEGER
    RetVal ASCII code value of a character read from hFile.

Parameters:

  • Data type: FILE
    hFile The handle of file from which ASCII code is read.

ExampleCut and save the example as GETC.BAS. Translate and compile it. Run it as :

Cut and save the example as GETC.BAS. Translate and compile it. Run it as GETC | more.

DIM a$
DIM b%

OPEN "getc.bin" FOR BINARY NEW AS FP1
FOR INTEGER O = 0 TO 255
 a$ = CHR$(O)
 PUT$ FP1, a$, 1
NEXT O
CLOSE FP1

OPEN "getc.bin" FOR BINARY AS FP1
FOR INTEGER O = 0 TO 255
 b% = GETC(FP1)
 PRINT b%
NEXT O
CLOSE FP1

END

PUTC function

Purpose:

PUTC places in the specified file, at the location of the current file pointer, the ASCII integer code value of a character.

Syntax:

PUTC(hFile AS FILE, ASCIICode AS INTEGER)

Parameters:

  • Data type: FILE
    hFile The handle of the file in which the ASCII code is to be placed.
  • Data type: INTEGER
    ASCIICode ASCII code value of a character to be placed in hFile.

Example:

OPEN "test.txt" FOR OUTPUT AS #1
FOR CHAR i = 65 TO 70
  PUTC #1, i
NEXT
PUTC #1, 13  ' 13 = Carriage Return 
PUTC #1, 10  ' 10 = Line Feed 
FLUSH #1     ' optional but always a good idea to FLUSH when you're done :-) 
CLOSE #1