# FPUTC

Portability Function: Writes a character to the file specified by a Fortran external unit, bypassing normal Fortran input/output.

## Module

USE IFPORT

result = FPUTC (lunit,char)

lunit | (Input) INTEGER(4). Unit number of a file.
char | (Output) Character*(*). Variable whose value is to be written to the file corresponding to lunit.

## Results

The result type is INTEGER(4). The result is zero if the write was successful; otherwise, an error code, such as:

EINVAL - The specified unit is invalid (either not already open, or an invalid unit number)

If you use WRITE, READ, or any other Fortran I/O statements with lunit, be sure to read Input and Output Routines in Overview of Portability Routines.

## Example

    use IFPORT
    integer*4 lunit, i4
    character*26 string
    character*1 char1
    lunit = 1
    open (lunit,file = 'fputc.dat')
    do i = 1,26
      char1 = char(123-i)
      i4 = fputc(1,char1)        !make valid writes
      if (i4.ne.0) iflag = 1
    enddo
    rewind (1)
    read (1,'(a)') string
    print *, string

Parent topic: E to F

## See Also

I/O Formatting