C language library function (S type letters) - 3

xiaoxiao2021-03-06  41

Function name: Sound

Function: Open the PC speaker with a specified frequency

Usage: Void Sound (Unsigned Frequency);

Example:

/ * Emits a 7-Hz Tone for 10 seconds.

Your PC May Not Be Able To Emit A 7-Hz Tone. * /

#include

Int main (void)

{

Sound (7);

DELAY (10000);

Nosound ();

Return 0;

}

Function name: spawnl

Function: Create and run a subscriber

Usage: int spawnl (int mode, char * pathname, char * arg0,

Arg1, ... argn, null;

Example:

#include

#include

#include

Int main (void)

{

Int result;

CLRSCR ();

Result = spawnl (p_wait, "tcc.exe", null;

IF (result == -1)

{

Perror ("Error from Spawnl";

Exit (1);

}

Return 0;

}

Function Name: Spawnle

Function: Create and run a subscriber

Usage: int Spawnle (int MODE, Char * Pathname, Char * Arg0,

Arg1, ..., argn, null;

Example:

/ * Spawnle () esample * /

#include

#include

#include

Int main (void)

{

Int result;

CLRSCR ();

Result = SPAWNLE (p_wait, "tcc.exe", null, null;

IF (result == -1)

{

Perror ("Error from Spawnle";

Exit (1);

}

Return 0;

}

Function name: Sprintf

Function: send formatted output to string

Usage: int sprintf (char * string, char * farmat [, argument, ...]);

Example:

#include

#include

Int main (void)

{

Char buffer [80];

Sprintf (Buffer, "An Approximation Of PI IS% F / N", M_PI);

PUTS (BUFFER);

Return 0;

}

Function name: SQRT

Function: calculate the square root

Usage: Double SQRT (Double X);

Example:

#include

#include

Int main (void)

{

Double x = 4.0, result;

Result = SQRT (X);

Printf ("The Square Root OF% LF IS% LF / N", X, Result;

Return 0;

}

Function name: SRAND

Function: Initializing the random number generator

Usage: Void Srand (unsigned seed);

Example:

#include

#include

#include int main (void)

{

INT I;

Time_t t;

SRAND (& T);

Printf ("Ten Random Numbers from 0 to 99 / N / N");

For (i = 0; i <10; i )

Printf ("% D / N", RAND ()% 100);

Return 0;

}

Function name: SSCANF

Function: Perform formatting input from strings

Usage: int Sscanf (Char * string, char * format [, argument, ...];

Example:

#include

#include

Int main (void)

{

Char label [20];

Char Name [20];

INT entries = 0;

Int loop, agn;

Double Salry;

Struct Entry_Struct

{

Char Name [20];

Int agec;

Float Salry;

Entry [20];

/ * Input a label as a string of characters restricting to 20 characters * /

Printf ("/ N / N / NPLEASE ENTER A Label for the Chart:");

Scanf ("% 20s", Label;

Fflush (stdin); / * flush the input stream in case of bad input * /

/ * Input Number of Entries as an inTeger * /

Printf ("How Many Entries Will there be? (Less Than 20)");

Scanf ("% d", & entries);

Fflush (stdin); / * flush the input stream in case of bad input * /

/ * Input a name restricting input to only letters upper or limited number * /

For (loop = 0; loop

{

Printf ("Entry% D / N", LOOP;

Printf ("Name:");

Scanf ("% [A-ZA-Z]", Entry [loop] .name;

Fflush (stdin); / * flush the input stream in case of bad input * /

/ * Input an agent AGE as an integer * /

Printf ("Age:");

Scanf ("% D", & Entry [loop] .age);

Fflush (stdin); / * flush the input stream in case of bad input * /

/ * Input a Salary as a float * /

Printf ("Salary:");

Scanf ("% f", & entry [loop] .salary);

Fflush (stdin); / * flush the input stream in case of bad input * /

}

/ * INPUT A Name, Age and Salary As a string, integer, and double * / printf ("/ nplease enter your name, agn and sales / n");

Scanf ("% 20S% D% LF", Name, & Age, & Salary;

/ * Print Out the Data That Was Input * /

Printf ("/ N / NTABLE% S / N", Label);

Printf ("Compiled BY% S AGE% D $% 15.2LF / N", Name, AGE, SALARY);

Printf ("--------------------------------------------- ------ / n ");

For (loop = 0; loop

Printf ("% 4D |% -20S |% 5D |% 15.2LF / N",

LOOP 1,

Entry [loop] .name,

Entry [loop] .age,

Entry [loop] .salary;

Printf ("--------------------------------------------- ------ / n ");

Return 0;

}

Function name: Stat

Function: Read Open File Information

Usage: int Stat (char * pathname, struct stat * buff);

Example:

#include

#include

#include

#define filename "Test. $$$"

Int main (void)

{

Struct stat statbuf;

File * stream;

/ * Open a file for update * /

IF ((stream = fopen (filename, "w ")) == NULL)

{

FPRINTF (stderr, "cannot open output file./n");

Return (1);

}

/ * GET Information about the file * /

Stat (filename, & statbuf);

Fclose (stream);

/ * Display the information returned * /

IF (StatBuf.st_Mode & S_IFCHR)

Printf ("Handle Refers to A Device./N");

IF (statbuf.st_mode & s_ifreg)

Printf ("Handle Refers to An ORDINARY FILE./N");

IF (statbuf.st_mode & s_iread)

Printf ("User Has Read Permission on File./N");

IF (statbuf.st_mode & s_iwrite)

Printf ("User Has Write Permission on File./N");

Printf ("Drive Letter Of File:% C / N", 'A' Statbuf.st_Dev);

Printf ("Size of File in Bytes:% ld / n", statbuf.st_size);

Printf ("Time File Last Opened:% S / N", CTIME (& statbuf.st_ctime);

Return 0;

}

Function name: _STATUS87

Function: Take floating point status

Usage: unsigned int _status87 (void);

Example:

#include

#include

Int main (void)

{

Float x;

Double y = 1.5e-100;

Printf ("Status 87 Before Error:% X / N", _status87 ());

X = Y; / * <- force an error to occur * /

y = x;

Printf ("Status 87 after Error:% X / N", _status87 ());

Return 0;

}

Function name: Stime

Function: Setting time

Usage: int Stime (long * tp);

Example:

#include

#include

#include

Int main (void)

{

Time_t t;

StructTM * area;

T = Time (NULL);

Area = localtime (& t);

Printf ("NUMBER OF Seconds Since 1/1/1970 IS: LD / N", T);

Printf ("Local Time IS:% S", ASCTIME (Area));

T ;

Area = localtime (& t);

Printf ("Add A Second:% S", ASCTIME (Area));

T = 60;

Area = localtime (& t);

Printf ("Add A Minute:% S", ASCTIME (Area));

T = 3600;

Area = localtime (& t);

Printf ("Add AN Hour:% S", Asctime (Area));

T = 86400L;

Area = localtime (& t);

Printf ("Add A Day:% S", ASCTIME (Area));

T = 2592000L;

Area = localtime (& t);

Printf ("Add A Month:% S", ASCTIME (Area));

T = 31536000L;

Area = localtime (& t);

Printf ("Add A Year:% S", ASCTIME (Area));

Return 0;

}

Function Name: STPCPY

Function: Copy a string to another

Usage: char * stpcpy (char * destin, char * source);

Example:

#include

#include

Int main (void)

{

Char string [10];

Char * str1 = "abcdefghi";

STPCPY (String, Str1);

Printf ("% s / n", string);

Return 0;

}

Function Name: STRCAT

Function: string splicing function

Usage: Char * Strcat (Char * Destin, Char * SOURCE);

Example:

#include

#include

Int main (void)

{

CHAR DESTINATION [25];

Char * blank = "", * c = "c ", * borland = "borland";

STRCPY (Destination, Borland);

STRCAT (DESTINATION, Blank);

STRCAT (DESTINATION, C);

Printf ("% s / n", destination;

Return 0;

}

Function Name: STRCHR

Function: Find the first match of the given character in a string /

Usage: char * str, char C);

Example:

#include

#include

Int main (void)

{

CHAR STRING [15];

CHAR * PTR, C = 'R';

STRCPY (String, "This Is A String");

PTR = Strchr (String, C);

IF (PTR)

Printf ("THE CHARACTER% C IS At Position:% D / N", C, PTR-String);

Else

Printf ("THE Character Was Not Found / N);

Return 0;

}

Function name: strcmp

Function: string comparison

Usage: int strcmp (char * str1, char * STR2);

Example:

#include

#include

Int main (void)

{

Char * buf1 = "aaa", * buf2 = "bbb", * buf3 = "ccc";

int PTR;

PTR = strcmp (buf2, buf1);

IF (PTR> 0)

Printf ("Buffer 2 IS Greater Than Buffer 1 / N");

Else

Printf ("Buffer 2 IS Less Than Buffer 1 / N");

PTR = strcmp (buf2, buf3);

IF (PTR> 0)

Printf ("Buffer 2 IS Greater Than Buffer 3 / N");

Else

Printf ("Buffer 2 IS Less Than Buffer 3 / N");

Return 0;

}

Function name: Strncmpi

Function: Compares part of a string with another string, regardless of case

Usage: int Strncmpi (Char * STR1, CHAR * STR2, UNSIGNED MAXLEN)

Example:

#include

#include

Int main (void)

{

Char * buf1 = "bbb", * buf2 = "bbb";

int PTR;

PTR = Strcmpi (buf2, buf1);

IF (PTR> 0)

Printf ("Buffer 2 IS Greater Than Buffer 1 / N"); if (Ptr <0)

Printf ("Buffer 2 IS Less Than Buffer 1 / N");

IF (PTR == 0)

Printf ("Buffer 2 Equals Buffer 1 / N");

Return 0;

}

Function name: STRCPY

Function: String copy

Usage: char * strcpy (char * str1, char * STR2);

Example:

#include

#include

Int main (void)

{

Char string [10];

Char * str1 = "abcdefghi";

STRCPY (String, Str1);

Printf ("% s / n", string);

Return 0;

}

Function name: strcspn

Function: Find the first segment of the first given character set content in the string

Usage: int StRCSPN (Char * STR1, CHAR * STR2);

Example:

#include

#include

#include

Int main (void)

{

Char * String1 = "1234567890";

CHAR * STRING2 = "747dc8";

Int length;

Length = strcspn (string1, string2);

Printf ("Character WHERE STRINGS INTERSECT IS AT POSITION% D / N", Length);

Return 0;

}

Function name: strDup

Function: copy the string to the new location

Usage: char * strdup (char * STR);

Example:

#include

#include

#include

Int main (void)

{

Char * dup_str, * string = "abcde";

DUP_STR = STRDUP (STRING);

Printf ("% S / N", DUP_STR);

Free (DUP_STR);

Return 0;

}

Function name: Stricmp

Dynamic: Two strings are compared in case sensitive mode

Usage: int StricsP (Char * STR1, CHAR * STR2);

Example:

#include

#include

Int main (void)

{

Char * buf1 = "bbb", * buf2 = "bbb";

int PTR;

PTR = Stricmp (buf2, buf1);

IF (PTR> 0)

Printf ("Buffer 2 IS Greater Than Buffer 1 / N");

IF (PTR <0)

Printf ("Buffer 2 IS Less Than Buffer 1 / N");

IF (PTR == 0)

Printf ("Buffer 2 Equals Buffer 1 / N");

Return 0;

}

Function name: strerror

Function: Returns a pointer to the error message string

Usage: char * strerror (int errnum);

#include

#include

Int main (void)

{

Char * buffer;

Buffer = strerror (errno);

Printf ("Error:% S / N", Buffer;

Return 0;

}

Function name: strcmpi

Function: Write a string with another, regardless of case

Usage: int strcmpi (char * str1, char * STR2);

Example:

#include

#include

Int main (void)

{

Char * buf1 = "bbb", * buf2 = "bbb";

int PTR;

PTR = Strcmpi (buf2, buf1);

IF (PTR> 0)

Printf ("Buffer 2 IS Greater Than Buffer 1 / N");

IF (PTR <0)

Printf ("Buffer 2 IS Less Than Buffer 1 / N");

IF (PTR == 0)

Printf ("Buffer 2 Equals Buffer 1 / N");

Return 0;

}

Function Name: Strncmp

Function: string comparison

Usage: int strncmp (char * str1, char * str2, int maxlen);

Example:

#include

#include

Int main (void)

{

Char * buf1 = "aaabbb", * buf2 = "bbbccc", * buf3 = "ccc";

int PTR;

PTR = Strncmp (BUF2, BUF1, 3);

IF (PTR> 0)

Printf ("Buffer 2 IS Greater Than Buffer 1 / N");

Else

Printf ("Buffer 2 IS Less Than Buffer 1 / N");

PTR = Strncmp (buf2, buf3, 3);

IF (PTR> 0)

Printf ("Buffer 2 IS Greater Than Buffer 3 / N");

Else

Printf ("Buffer 2 IS Less Than Buffer 3 / N");

Return (0);

}

Function name: Strncmpi

Dynamic: Compares part of the string with the other string, regardless of case

Usage: int strncmpi (char * str1, char * STR2);

Example:

#include

#include

Int main (void)

{

Char * buf1 = "bbbccc", * buf2 = "bbbccc";

int PTR;

PTR = Strncmpi (buf2, buf1, 3);

IF (PTR> 0)

Printf ("Buffer 2 IS Greater Than Buffer 1 / N");

IF (PTR <0)

Printf ("Buffer 2 IS Less Than Buffer 1 / N");

IF (PTR == 0) Printf ("Buffer 2 Equals Buffer 1 / N");

Return 0;

}

Function name: STRNCPY

Function: String copy

Usage: char * STRNCPY (Char * Destin, Char * Source, Int Maxlen);

Example:

#include

#include

Int main (void)

{

Char string [10];

Char * str1 = "abcdefghi";

STRNCPY (String, STR1, 3);

String [3] = '/ 0';

Printf ("% s / n", string);

Return 0;

}

Function name: strnicmp

Function: Do not pay attention to comparing two strings in small writing

Usage: int Strnicmp (Char * STR1, Char * STR2, UNSIGNED MAXLEN);

Example:

#include

#include

Int main (void)

{

Char * buf1 = "bbbccc", * buf2 = "bbbccc";

int PTR;

PTR = Strnicmp (BUF2, BUF1, 3);

IF (PTR> 0)

Printf ("Buffer 2 IS Greater Than Buffer 1 / N");

IF (PTR <0)

Printf ("Buffer 2 IS Less Than Buffer 1 / N");

IF (PTR == 0)

Printf ("Buffer 2 Equals Buffer 1 / N");

Return 0;

}

Function name: strnset

Function: Set all characters in a string to specified characters

Usage: char * str, char * STR, CHAR CH, UNSIGNED N);

Example:

#include

#include

Int main (void)

{

Char * string = "AbcdefghijklmnopqrStuvwxyz";

Char letter = 'x';

Printf ("String Before Strnset:% S / N", String);

Strnset (String, Letter, 13);

Printf ("String After Strnset:% S / N", String);

Return 0;

}

Function name: strpbrk

Function: Find characters in the gauge set in the string

Usage: char * strpbrk (char * str1, char * STR2);

Example:

#include

#include

Int main (void)

{

Char * string1 = "abcdefghijklmnopqrstuvwxyz";

Char * string2 = "M";

Char * PTR;

PTR = strpbrk (string1, string2);

IF (PTR)

Printf ("StrPBRK Found First Character:% C / N", * PTR);

Else

Printf ("StrPBRK Didn't Find Character In Set / N"); Return 0;

}

Function name: STRRCHR

Function: Find the last appearance of the specified character in the string

Usage: char * STRCHR (Char * Str, CHAR C);

Example:

#include

#include

Int main (void)

{

CHAR STRING [15];

CHAR * PTR, C = 'R';

STRCPY (String, "This Is A String");

PTR = Strrchr (String, C);

IF (PTR)

Printf ("THE CHARACTER% C IS At Position:% D / N", C, PTR-String);

Else

Printf ("THE Character Was Not Found / N);

Return 0;

}

Function Name: Strrev

Function:

Usage: char * strrev (char * STR);

Example:

#include

#include

Int main (void)

{

Char * forward = "string";

Printf ("Before StrRev ():% S / N", Forward);

Strrev (Forward);

Printf ("After Strrev ():% S / N", Forward);

Return 0;

}

Function name: strset

Function: Set all characters in a string to specified characters

Usage: char * str, char C);

Example:

#include

#include

Int main (void)

{

CHAR STRING [10] = "123456789";

CHAR SYMBOL = 'c';

Printf ("Before StRSET ():% S / N", String);

StRSET (String, Symbol);

Printf ("After StRSET ():% S / N", String);

Return 0;

}

Function name: strspn

Function: Find the first appearance of the subset of the specified character set in the string

Usage: int StRSPN (Char * STR1, CHAR * STR2);

Example:

#include

#include

#include

Int main (void)

{

Char * String1 = "1234567890";

Char * string2 = "123dc8";

Int length;

Length = strspn (String1, String2);

Printf ("Character WHERE STRINGS DIFFER IS AT POSITION% D / N", Length);

Return 0;

}

Function name: strstr

Function: Find the first appearance of the specified string in the string

Usage: char * strstr (char * str1, char * STR2);

Example:

#include

#include

INT main (void) {

Char * str1 = "borland international", * str2 = "nation", * PTR;

PTR = strs (str1, str2);

Printf ("THE SUBSTRING IS:% S / N", PTR);

Return 0;

}

Function name: Strtod

Function: Convert strings to Double type values

Usage: Double Strtod (Char * Str, Char ** Endptr);

Example:

#include

#include

Int main (void)

{

CHAR INPUT [80], * ENDPTR

Double Value;

Printf ("Enter A Floating Point Number:");

Gets (Input);

Value = strtod (Input, & Endptr);

Printf ("THE STRING IS% S The Number IS% LF / N", Input, Value;

Return 0;

}

Function name: STRTOK

Function: Find the words separated by the divided division in the second string

Usage: char * str1, char * STR2);

Example:

#include

#include

Int main (void)

{

CHAR INPUT [16] = "ABC, D";

Char * p;

/ * STRTOK Places A Null Terminator

In Front of the Token, IF Found * /

P = STRTOK (Input, ",");

IF (p) Printf ("% s / n", p);

/ * A Second Call to Strtok Using A NULL

As The First Parameter Returns a Pointer

To the Character Following The Token * /

P = strtok (null, ",");

IF (p) Printf ("% s / n", p);

Return 0;

}

Function name: Strtol

Function: Convert strings to long intensity

Usage: Long Strtol (Char * Str, Char ** Endptr, Int Base);

Example:

#include

#include

Int main (void)

{

Char * string = "87654321", * endptr;

Long lnumber;

/ * STRTOL Converts String to Long Integer * /

lnumber = strtol (string, & evenptr, 10);

Printf ("String =% S long =% ld / n", string, lnumber;

Return 0;

}

Function name: Strupr

Function: Convert the lowercase letters in the string to uppercase letters

Usage: Char * Strupr (Char * STR);

Example:

#include

#include

Int main (void)

{

Char * string = "abcdefghijklmnopqrstuvwxyz", * ptr; / * Converts String to Upper case characters * /

PTR = strupr (strup);

Printf ("% S / N", PTR);

Return 0;

}

Function name: SWAB

Function: swap bytes

Usage: void swab (char * from, char * to, int nbytes);

Example:

#include

#include

#include

Char source [15] = "RFNA KoblRNA D";

Char Target [15];

Int main (void)

{

SwaB (Source, Target, Strlen (Source);

Printf ("This is Target:% S / N", TARGET);

Return 0;

}

Function name: system

Function: Send a DOS command

Usage: int system (char * command);

Example:

#include

#include

Int main (void)

{

Printf ("About to spawn command.com and run a dos command / n");

System ("DIR");

Return 0;

}

转载请注明原文地址:https://www.9cbs.com/read-74419.html

New Post(0)