Watcom C Library Reference : _splitpath, _splitpath2, sprint, sqrt, srand, sscanf

 

 

 

 

_splitpath

 

Synopsis : #include <stdlib.h> 

              void _splitpath( const char *path,

                                      char *drive,

                                      char *dir,

                                      char *fname,

                                      char *ext );

 


Description : : The _splitpath function splits up a full pathname into four components consisting of a drive letter, directory path, file name and file name extension. The argument path points to a buffer containing the full pathname to be split up.


The maximum size required for each buffer is specified by the manifest constants _MAX_PATH_MAX_DRIVE, _MAX_DIR, _MAX_FNAME, and _MAX_EXT which are defined in <stdlib.h>.

 

 drive  The drive argument points to a buffer that will be filled in with the drive letter (e.g., A, B, C, etc.) followed by a colon if a drive is specified in the full pathname (filled in by _splitpath).
 dir  The dir argument points to a buffer that will be filled in with the pathname including the trailing slash. Either forward slashes (() or backslashes (1) may be used.
 fname  The fname argument points to a buffer that will be filled in with the base name of the file without any extension (suffix) if a file name is specified in the full pathname (filled in by _splitpath).
 ext  The ext argument points to a buffer that will be filled in with the filename extension (suffix) including the leading period if an extension is specified in the full pathname (filled in by _splitpath).


The arguments drive, dir, fname and ext will not be filled in if they are NULL pointers.


For each component of the full pathname that is not present, its corresponding buffer will be set to an empty string.

 


Returns : The _splitpath function returns no value.

 

 

See Also : _fullpath, _makepath, _splitpath2

 


Example :

#include <stdio.h> 

#include <stdlib.h>


void main( ) 

{
    char     full_path[_MAX_PATH];

    char     drive[ _MAX_DRIVE];

    char     dir[_MAX_DIR];

    char     fname[ _MAX_FNAME];

    char     ext[ _MAX_EXT];


    _makepath( full_path, "c", "watcomc\\h\\", "stdio", "h");

    printf( "Full path is: %s\n\n", full_path );

 

    _splitpath( full_path, drive, dir, fname, ext );

    printf( "Components after _splitpath\n" );

    printf( "drive: %s\n", drive );

    printf( "dir: %s\n", dir );

    printf( "fname: %s\n", fname );

    printf( "ext: %s\n", ext );

}

 


produces the following :
Full path is: c:watcomc\h\stdio.h


Components after _splitpath

drive: c:

dir: watcomc\h\

fname: stdio

ext: .h

 

Note the use of two adjacent backslash characters (\) within character-string constants to signify a single backslash.

 

Classification : WATCOM
Systems : All

 

 

 

 

 

 

 

_splitpath2

 

Synopsis : #include <stdlib.h> 

              void _splitpath2( const char *inp,

                                 const char *outp,

                                        char **drive,

                                        char **dir,

                                        char **fname,

                                        char **ext );


Description : The _splitpath2 function splits up a full pathname into four components consisting of a drive letter, directory path, file name and file name extension.

 

 inp  The argument inp points to a buffer containing the full pathname to be split up.
 outp  The argument outp points to a buffer that will contain all the components of the path, each separated by a null character. The maximum size required for this buffer is specified by the manifest constant _MAX_PATH2 which is defined in <stdlib.h>.
 drive  The drive argument is the location that is to contain the pointer to the drive letter (e.g., A, B, C, etc.) followed by a colon if a drive is specified in the full pathname (filled in by _splitpath2).
 dir  The dir argument is the location that is to contain the pointer to the directory path including the trailing slash if a directory path is specified in the full pathname (filled in by _splitpath2). Either forward slashes (/) or backslashes (\) may be used.
 fname  The fname argument is the location that is to contain the pointer to the base name of the file without any extension (suffix) if a file name is specified in the full pathname (filled in by _splitpath2).
 ext  The ext argument is the location that is to contain the pointer to the filename extension (suffix) including the leading period if an extension is specified in the full pathname (filled in by _splitpath2).

 

The arguments drive, dir, fname and ext will not be filled in if they are NULL pointers.


For each component of the full pathname that is not present, its corresponding pointer will be set to point at a NULL string ('\0').


This function reduces the amount of memory space required when compared to the _splitpath function.

 


Returns : The _splitpath2 function returns no value.

 

 

See Also : _fullpath, _makepath, _splitpath

 


Example :

#include <stdio.h> 

#include <stdlib.h>


void main( )

{
    char     full_path[_MAX_PATH];

    char     tmp_path[_MAX_PATH2];

    char     *drive;

    char     *dir;

    char     *fname;

    char     *ext;


    _makepath( full_path, "c", "watcomc\\h", "stdio", "h" );

    printf( "Full path is: %s\n\n", full_path );

 

    _splitpath2( full_path, tmp_path, &drive, &dir, &fname, &ext ); 

    printf( "Components after _splitpath2\n" );

    printf( "drive: %s\n", drive );

    printf( "dir: %s\n", dir );

    printf( "fname: %s\n", fname);

    printf( "ext: %s\n", ext);

}

 


produces the following : 

Full path is: c:watcomc\h\stdio.h


Components after _splitpath2 

drive: c:

dir: watcomc\h\

fname: stdio

ext: .h


Note the use of two adjacent backslash characters(\) within character-tring constants to signify a single backslash.

 

Classification : WATCOM
Systems : All

 

 

 

 

 

 

 

sprint

 

Synopsis : #include <stdio.h> 

              int sprintf( char *buf, const char *format, ... );

 


Description : The sprintf function is equivalent to the fprintf function, except that the argument buf specifies a character array into which the generated output is placed, rather than to a file. A null character is placed at the end of the generated character string. The format string is described under the description of the printf function.

 

 

Returns : The sprintf function returns the number of characters written into the array, not counting the  erminating null character. An error can occur while converting a value for output. When an error has occurred, errno contains a value indicating the type of error that has been detected.

 

 

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

 


Example :

To create temporary file names using a counter :

#include <stdio.h>


char     namebuf[13];

int       TempCount = 0;


char *make_temp_name( )

{
    sprintf( namebuf, "ZZ%.6o. TMP", TempCount++ );

    return( namebuf );

}


void main( )

{
    FILE     *tfi, *tf2;


    tf1 = fopen( make_temp_name( ), "w" );

    tf2 = fopen( make_temp_name( ), "w" );

    fputs ( "temp file 1", tfl );

    fputs ( "temp file 2", tf2 );

    fclose( tf1 );

    fclose( tf2 );

}

 

Classification : ANSI
Systems : All

 

 

 

 

 

 

 

sqrt

 

Synopsis : #include <math.h> 

              double sqrt( double x );

 


Description : The sqrt function computes the non-negative square root of x. A domain error occurs if the argument is negative.

 

 

Returns : The sqrt function returns the value of the square root. When the argument is outside the permissible range, the matherr function is called. Unless the default matherr function is replaced, it will set the global variable errno to EDOM, and print a "DOMAIN error" diagnostic message using the stderr stream.

 

 

See Also : exp, log, pow, matherr

Example :

#include <stdio.h> 

#include <math.h>


void main( )

{
    printf( "%f\n", sqrt(.5) );

}

 


produces the following :
0.707107

 

Classification : ANSI
Systems : All

 

 

 

 

 

 

 

srand

 

Synopsis : #include <stdlib.h> 

              void srand( unsigned int seed );

 


Description : The srand function uses the argument seed to start a new sequence of pseudo-random integers to be returned by subsequent calls to rand. A particular sequence of pseudo-random integers can be repeated by calling srand with the same seed value. The default sequence of pseudo-random integers is selected with a seed value of 1.

 

 

Returns : The srand function returns no value.

 

 

See Also : rand

 


Example :

#include <stdio.h> 

#include <stdlib.h>


void main( )

{
    int     i;


    srand( 982 );

    for( i = 1; i < 10; ++i ) {
        printf( "%d\n", rand( ) );

    }


    srand ( 982 );
    /* start sequence over again */

    for( i = 1; i < 10; ++i ) {

        printf("%d\n", rand( ) );

    }

}

 

Classification : ANSI
Systems : All

 

 

 

 

 

 

 

sscanf

 

Synopsis : #include <stdio.h> 

              int sscanf( const char *in_string, const char *format, ... );


Description : The sscanf function scans input from the character string in_string under control of the argument format. Following the format string is the list of addresses of items to receive values.


The format string is described under the description of the scanf function.

 

 

Returns : The sscanf function returns EOF when the scanning is terminated by reaching the end of the input  string, Otherwise, the number of input arguments for which values were successfully scanned and stored is returned.

 

 

See Also : cscanf, fscanf, scanf, vcscanf, vfscanf, vscanf, vsscanf

 


Example :

To scan the date in the form "Friday April 13 1999":


#include <stdio.h>


void main( )

{
    int     day, year;

    char   weekday[20], month[20];


    sscanf ( "Friday April 0013 1999", "%s %s %d %d",

                weekday, month, &day, &year );

 

    printf( "%s %s %d %d\n", weekday, month, day, year );

}

 


produces the following :
Friday April 13 1999

 

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 전화카드
,