C language function finishing Daquan five (P-S)

Source: Internet
Author: User
Tags strtok

Function Name: parsfnm
Function: Analyze file names
Usage: char * parsfnm (char * using line, struct fcb * fcbptr, int option );
Program example:
# Include
# Include
# Include
# Include
Int main (void)
{
Char line [80];
Struct fcb blk;
/* Get file name */
Printf ("Enter drive and file name (no path-ie. a: file. dat )");
Gets (line );
/* Put file name in fcb */
If (parsfnm (line, & blk, 1) = NULL)
Printf ("Error in parsfm call ");
Else
Printf ("Drive # % d Name: s", blk. fcb_drive, blk. fcb_name );
Return 0;
}

Function Name: peek
Function: Check the storage unit
Usage: int peek (int segment, unsigned offset );
Program example:
# Include
# Include
# Include
Int main (void)
{
Int value = 0;
Printf ("The current status of your keyboard is :");
Value = peek (0x0040, 0x0017 );
If (value & 1)
Printf ("Right shift on ");
Else
Printf ("Right shift off ");
If (value & 2)
Printf ("Left shift on ");
Else
Printf ("Left shift off ");
If (value & 4)
Printf ("Control key on ");
Else
Printf ("Control key off ");
If (value & 8)
Printf ("Alt key on ");
Else
Printf ("Alt key off ");
If (value & 16)
Printf ("Scroll lock on ");
Else
Printf ("Scroll lock off ");
If (value & 32)
Printf ("Num lock on ");
Else
Printf ("Num lock off ");
If (value & 64)
Printf ("Caps lock on ");
Else
Printf ("Caps lock off ");
Return 0;
}

Function Name: peekb
Function Name: qsort
Skill: Use a Quick Sort routine for sorting
Usage: void qsort (void * base, int nelem, int width, int (* fcmp )());
Program example:
# Include
# Include
# Include
Int sort_function (const void * a, const void * B );
Char list [5] [4] = {"cat", "car", "cab", "cap", "can "};

Int main (void)
{
Int x;
Qsort (void *) list, 5, sizeof (list [0]), sort_function );
For (x = 0; x <5; x)
Printf ("% s", list [x]);
Return 0;
}
Int sort_function (const void * a, const void * B)
{
Return (strcmp (a, B ));
}

Function Name: qsort
Skill: Use a Quick Sort routine for sorting
Usage: void qsort (void * base, int nelem, int width, int (* fcmp )());
Program example:
# Include
# Include
# Include
Int sort_function (const void * a, const void * B );
Char list [5] [4] = {"cat", "car", "cab", "cap", "can "};

Int main (void)
{
Int x;
Qsort (void *) list, 5, sizeof (list [0]), sort_function );
For (x = 0; x <5; x)
Printf ("% s", list [x]);
Return 0;
}
Int sort_function (const void * a, const void * B)
{
Return (strcmp (a, B ));
}

Function Name: raise
Function: send a signal to the program being executed
Usage: int raise (int sig );
Program example:
# Include
Int main (void)
{
Int a, B;
A = 10;
B = 0;
If (B = 0)
/* Preempt divide by zero error */
Raise (SIGFPE );
A = a/B;
Return 0;
}

Function Name: rand
Function Name: strstr
Function: Search for the first appearance of a specified string in the string.
Usage: char * strstr (char * str1, char * str2 );
Program example:
# Include
# Include
Int main (void)
{
Char * str1 = "Borland International", * str2 = "nation", * ptr;
Ptr = strstr (str1, str2 );
Printf ("The substring is: % s", ptr );
Return 0;
}

Function Name: strtodd
Function: converts a string to a double value.
Usage: double strtodd (char * str, char ** endptr );
Program example:
# Include
# Include
Int main (void)
{
Char input [80], * endptr;
Double value;
Printf ("Enter a floating point number :");
Gets (input );
Value = strtodd (input, & endptr );
Printf ("The string is % s the number is % lf", input, value );
Return 0;
}

Function Name: strtok
Function: searches for words separated by the delimiters specified in the second string.
Usage: char * strtok (char * str1, char * str2 );
Program 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", 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", p );
Return 0;
}

Function Name: strtol
Function: converts a string to a long integer.
Usage: long strtol (char * str, char ** endptr, int base );
Program example:
# Include
# Include
Int main (void)
{
Char * string = "87654321", * endptr;
Long lnumber;
/* Strtol converts string to long integer */
Lnumber = strtol (string, & endptr, 10 );
Printf ("string = % s long = % ld", string, lnumber );
Return 0;
}

Function Name: strupr
Function: converts lowercase letters in a string to uppercase letters.
Usage: char * strupr (char * str );
Program example:
# Include
# Include
Int main (void)
{
Char * string = "abcdefghijklmnopqrstuvwxyz", * ptr;
/* Converts string to upper case characters */
Ptr = strupr (string );
Printf ("% s", ptr );
Return 0;
}

Function Name: swab
Function: swap byte
Usage: void swab (char * from, char * to, int nbytes );
Program 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", target );
Return 0;
}

Function Name: system
Function: issue a DOS command
Usage: int system (char * command );
Program example:
# Include
# Include
Int main (void)
{
Printf ("About to spawn command.com and run a DOS command ");
System ("dir ");
Return 0;
}

Function: random number generator
Usage: void rand (void );
Program example:
# Include
# Include
Int main (void)
{
Int I;
Printf ("Ten random numbers from 0 to 99 ");
For (I = 0; I <10; I)
Printf ("% d", rand () % 100 );
Return 0;
}

Function Name: randbrd
Function: Random Block read
Usage: int randbrd (struct fcb * fcbptr, int reccnt );
Program example:
# Include
# Include
# Include
# Include
Int main (void)
{
Char far * save_dta;
Char line [80], buffer [256];
Struct fcb blk;
Int I, result;
/* Get user input file name for dta */
Printf ("Enter drive and file name (no path-I. e. a: file. dat )");
Gets (line );
/* Put file name in fcb */
If (! Parsfnm (line, & blk, 1 ))
{
Printf ("Error in call to parsfnm ");
Exit (1 );
}
Printf ("Drive # % d File: % s", blk. fcb_drive, blk. fcb_name );
/* Open file with dos fcb open file */
Bdosptr (0x0F, & blk, 0 );
/* Save old dta, and set new one */
Save_dta = getdta ();
Setdta (buffer );
/* Set up info for the new dta */
Blk. fcb_recsize = 128;
Blk. fcb_random = 0L;
Result = randbrd (& blk, 1 );
/* Check results from randbrd */
If (! Result)
Printf ("Read OK ");
Else
{
Perror ("Error during read ");
Exit (1 );
}
/* Read in data from the new dta */
Printf ("The first 128 characters are :");
For (I = 0; I <128; I)
Putchar (buffer [I]);
/* Restore previous dta */
Setdta (save_dta );
Return 0;
}

Function Name: randbwr
Function: Random Block write
Usage: int randbwr (struct fcp * fcbptr, int reccnt );
Program example:
# Include
# Include
# Include
# Include
Int main (void)
{
Char far * save_dta;
Char line [80];
Char buffer [256] = "RANDBWR test! ";
Struct fcb blk;
Int result;
/* Get new file name from user */
Printf ("Enter a file name to create (no path-ie. a: file. dat ");
Gets (line );
/* Parse the new file name to the dta */
Parsfnm (line, &

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.