'fprintf func'에 해당되는 글 1건

  1. 2021.06.26 Watcom C Library : _fpreset, fprintf, fputc, fputchar, fputs, fread

 

 

Watcom C Library Reference : _fpreset, fprintf, fputc, fputchar, fputs, fread

 

 

 

 

_fpreset

 

Synopsis : #include <float.h> 

              void _fpreset ( void );


Description : After a floating-point exception, it may be necessary to call the _fpreset function before any further floating-point operations are attempted.

 

Returns : No value is returned.

 

 

See Also : _clear87, _status87

 


Example :

#include <stdio.h> 

#include <float.h>


char *status [2] = { "No", " " };


void main( )

{
    unsigned int fp_status;


    fp_status = _status87( );


    printf( "80x87 status\n" );

    printf( "%s invalid operation\n",        status[ (fp_status & SW_INVALID) == 0 ] ); 

    printf( "%s denormalized operand\n",  status[ (fp_status & SW_DENORMAL) == 0 ]); 

    printf( "%s divide by zero\n",           status[ (fp_status & SW_ZERODIVIDE) == 0 ) ); 

    printf( "%s overflow\n",                 status[ (fp_status & SW_OVERFLOW) == 0 ] ); 

    printf( "%s underflow\n",                status[ (fp_status & SW_UNDERFLOW) == 0 ] ); 

    printf( "%s inexact result\n",            status[ (fp_status & SW_INEXACT) == 0 ) ); 

    _fpreset( );

}

 

Classification : Intel
Systems : All

 

 

 

 

 

fprintf

 

Synopsis : #include <stdio.h> 

              int fprintf( FILE *fp, const char *format, ... );

 


Description : The fprintf function writes output to the file pointed to by fp under control of the argument format. The format string is described under the description of the printf function

 

 

Returns : The fprintf function returns the number of characters written, or a negative value if an output error occurred. When an error has occurred, errno contains a value indicating the type of error that has been detected.

 

 

See Also : _bprintf, cprintf, printf, sprintf, _vbprintf, vcprintf, vfprintf, vprintf, vsprintf, vprintf, vsprintf

 


Example :

#include <stdio.h>


char *weekday = { "Saturday" }; 

char *month = { "April" };


void main( )

{

    fprintf( stdout, "%s, %s %d, %d\n", weekday, month, 13, 1999 );

}

 


produces the following :
Friday, April 13, 1999

 

Classification : ANSI
Systems : All

 

 

 

 

 

fputc

 

Synopsis : #include <stdio.h> 

              int fputc( int c, FILE *fp );

 


Description : The fputc function writes the character specified by the argument c to the output stream designated by fp.

 

 

Returns : The fputc function returns the character written. If a write error occurs, the error indicator is set and fputc returns EOF. When an error has occurred, errno contains a value indicating the type of error that has been detected.

 

 

See Also : fopen, fputchar, fputs, putc, putchar, puts

 


Example :

#include <stdio.h>


void main( )

{
    FILE     *fp;

    int       c;


    fp = fopen( "file", "r" );

    if( fp != NULL ) {

        while( (c = fgetc( fp ) ) != EOF )
            fputc( c, stdout );

        fclose( fp );

    }

}

 

Classification : ANSI
Systems : All

 

 

 

 

 

fputchar

 

Synopsis : #include <stdio.h> 

              int fputchar( int c );

 


Description : The fputchar function writes the character specified by the argument c to the output stream stdout. This function is identical to the putchar function.

The function is equivalent to : fputc( c, stdout);

 

 

Returns : The fputchar function returns the character written. If a write error occurs, the error indicator is set and fputchar returns EOF. When an error has occurred, errno contains a value indicating the type of error that has been detected.

 

 

See Also : fputc, fputs, putc, putchar

 


Example :

#include <stdio.h>

 

void main( )

{
    FILE     *fp;

    int       c;

 

    fp = fopen( "file", "r" );

    if( fp != NULL) {
        c = fgetc ( fp );

        while( c != EOF ) {
            fputchar( c );

            c = fgetc( fp );

        }
        fclose( fp );

    }

}

 

Classification : WATCOM
Systems : All

 

 

 

 

 

fputs

 

Synopsis : #include <stdio.h> 

              int fputs( const char *buf, FILE *fp );

 


Description : The fputs function writes the character string pointed to by buf to the output stream designated by fp. The terminating null character is not written.

 

 

Returns : The fputs function returns EOF if an error occurs otherwise it returns a non-negative value. When an error has occurred, errno contains a value indicating the type of error that has been detected.

 

 

See Also : fopen, fputc, putc, puts

 


Example :

#include <stdio.h>


void main( )

{
    FILE     *fp;

    char     buffer[80];
 

    fp = fopen( "file", "r" );

    if( fp != NULL ) {

        while( fgets ( buffer, 80, fp) != NULL )
            fputs ( buffer, stdout );

        fclose( fp );

    }

}

 

Classification : ANSI
Systems : All

 

 

 

 

 

fread

 

Synopsis : #include <stdio.h> 

              size_t fread( void *buf, size_t elsize, size_t nelem, FILE *fp );

 


Description : The fread function reads nelem elements of elsize bytes each from the file specified by fp into the buffer specified by buf.

 

 

Returns : The fread function returns the number of complete elements successfully read. This value may be less than the requested number of elements.

 

The feof and ferror functions can be used to determine whether the end of the file was encountered or if an input/output error has occurred. When an error has occurred, errno contains a value indicating the type of error that has been detected.

 

 

See Also : fopen, feof, ferror

 


Example : The following example reads a simple student record containing binary data. The student record is described by the struct student_data declaration.

#include <stdio.h>


struct student_data {
        int student_id;
        unsigned char marks [10];

};


size_t read_data( FILE *fp, struct student_data *p )

{
    return( fread( p, sizeof(*p), 1, fp ) );

}

 


void main( )
{
    FILE     *fp;

    struct student_data std;

    int       i;


    fp = fopen( "file", "r" );

    if( fp != NULL ) {

        while( read_data( fp, &std ) != 0 ) {
            printf( "id=%d ", std.student_id );

            for( i = 0; i < 10; i++ )
                printf( "%3d ", std.marks [ i ] );

            printf( "\n" );

        } 
        fclose( fp );

    }

}

 

Classification : ANSI
Systems : All

 

 

 

 

 

 

 

 

This manual describes the WATCOM C library for DOS, Windows, and OS/2, It includes the Standard C Library (as defined in the ANSI C Standard).

 

WATCOM C Language Reference manual describes the ANSI C Programming language and extensions to it which are supported by WATCOM C/C++ (32bit)

 

 

 

728x90
반응형
Posted by 전화카드
,