C language function finishing Daquan four (H-O)

Source: Internet
Author: User

Function Name: harderr
Skill: Create a hardware error handling program
Usage: void harderr (int (* fptr )());
Program example:
/* This program will trap disk errors and prompt
The user for action. Try running it with no
Disk in drive A: to invoke its functions .*/
# Include
# Include
# Include
# Define IGNORE 0
# Define RETRY 1
# Define ABORT 2
Int buf [500];
/* Define the error messages for trapping disk problems */
Static char * err_msg [] = {
"Write protect ",
"Unknown unit ",
"Drive not ready ",
"Unknown command ",
"Data error (CRC )",
"Bad request ",
"Seek error ",
"Unknown media type ",
"Sector not found ",
"Printer out of paper ",
"Write fault ",
"Read fault ",
"General failure ",
"Reserved ",
"Reserved ",
"Invalid disk change"
};
Error_win (char * msg)
{
Int retval;
Cputs (msg );
/* Prompt for user to press a key to abort, retry, ignore */
While (1)
{
Retval = getch ();
If (retval = 'A' | retval = 'A ')
{
Retval = ABORT;
Break;
}
If (retval = 'R' | retval = 'R ')
{
Retval = RETRY;
Break;
}
If (retval = 'I' | retval = 'I ')
{
Retval = IGNORE;
Break;
}
}
Return (retval );
}
/* Pragma warn-par reduces warnings which occur
Due to the non use of the parameters errval,
Bp and si to the handler .*/
# Pragma warn-par
Int handler (int errval, int ax, int bp, int si)
{
Static char msg [80];
Unsigned di;
Int drive;
Int errorno;
Di = _ DI;
/* If this is not a disk error then it was
Another device having trouble */
If (ax <0)
{
/* Report the error */
Error_win ("Device error ");
/* And return to the program directly requesting abort */
Hardretn (ABORT );
}
/* Otherwise it was a disk error */
Drive = ax & 0x00FF;
Errorno = di & 0x00FF;
/* Report which error it was */
Sprintf (msg, "Error: % s on drive % cA) bort, R) etry, I) gnore :",
Err_msg [errorno], 'A' drive );
/*
Return to the program via dos interrupt 0x23 with abort, retry,
Or ignore as input by the user.
*/
Hardresume (error_win (msg ));
Return ABORT;
}
# Pragma warn par
Int main (void)
{
/*
Install our handler on the hardware problem interrupt
*/
Harderr (handler );
Clrscr ();
Printf ("Make sure there is no disk in drive :");
Printf ("Press any key ....");
Getch ();
Printf ("Trying to access drive :");
Printf ("fopen returned % p", fopen ("A: temp. dat", "w "));
Return 0;
}

Function Name: line
Function: draw a line between two specified points
Usage: void far line (int x0, int y0, int x1, int y1 );
Program example:
# Include
# Include
# Include
# Include
Int main (void)
{
/* Request auto detection */
Int gdriver = DETECT, gmode, errorcode;
Int xmax, ymax;
/* Initialize graphics and local variables */
Initgraph (& gdriver, & gmode ,"");
/* Read result of initialization */
Errorcode = graphresult ();
/* An error occurred */
If (errorcode! = GrOk)
{
Printf ("Graphics error: % s ",
Grapherrormsg (errorcode ));
Printf ("Press any key to halt :");
Getch ();
Exit (1 );
}
Setcolor (getmaxcolor ());
Xmax = getmaxx ();
Ymax = getmaxy ();
/* Draw a diagonal line */
Line (0, 0, xmax, ymax );
/* Clean up */
Getch ();
Closegraph ();
Return 0;
}

Function Name: linerel
Function: draw a line from the current position point (CP) to a point that has a given relative distance with CP
Usage: void far linerel (int dx, int dy );
Program example:
# Include
# Include
# Include
# Include
Int main (void)
{
/* Request auto detection */
Int gdriver = DETECT, gmode, errorcode;
Char msg [80];
/* Initialize graphics and local variables */
Initgraph (& gdriver, & gmode ,"");
/* Read result of initialization */
Errorcode = graphresult ();
If (errorcode! = GrOk)
{
Printf ("Graphics error: % s ",
Grapherrormsg (errorcode ));
Printf ("Press any key to halt :");
Getch ();
Exit (1 );
}
/* Move the C.P. to location (20, 30 )*/
Moveto (20, 30 );
/* Create and output
Message at (20, 30 )*/
Sprintf (msg, "(% d, % d)", getx (), gety ());
Outtextxy (20, 30, msg );
/* Draw a line to a point a relative
Distance away from the current
Value of C.P .*/
Linerel (100,100 );
/* Create and output a message at C.P .*/
Sprintf (msg, "(% d, % d)", getx (), gety ());
Outtext (msg );
/* Clean up */
Getch ();
Closegraph ();
Return 0;
}

Function Name: localtime
Void normvideo (void );
Select normal brightness characters.
Set the text attribute (foreground and background) to the value it has when starting the program to select standard characters.
Void nosound (void );
Close the speaker that calls sound.
Function Name: open
Function: open a file for reading or writing.
Usage: int open (char * pathname, int access [, int permiss]);
Program example:
# Include
# Include
# Include
# Include
Int main (void)
{
Int handle;
Char msg [] = "Hello world ";
If (handle = open ("TEST. $", O_CREAT | O_TEXT) =-1)
{
Perror ("Error :");
Return 1;
}
Write (handle, msg, strlen (msg ));
Close (handle );
Return 0;
}

Function Name: outport
Function: outputs an integer to the hardware port.
Usage: void outport (int port, int value );
Program example:
# Include
# Include
Int main (void)
{
Int value = 64;
Int port = 0;
Outportb (port, value );
Printf ("Value % d sent to port number % d", value, port );
Return 0;
}

Function Name: outportb
Function: outputs bytes to the hardware port.
Usage: void outportb (int port, char byte );
Program example:
# Include
# Include
Int main (void)
{
Int value = 64;
Int port = 0;
Outportb (port, value );
Printf ("Value % d sent to port number % d", value, port );
Return 0;
}

Function Name: outtext
Function: display a string in the view area
Usage: void far outtext (char far * textstring );
Program example:
# Include
# Include
# Include
# Include
Int main (void)
{
/* Request auto detection */
Int gdriver = DETECT, gmode, errorcode;
Int midx, midy;
/* Initialize graphics and local variables */
Initgraph (& gdriver, & gmode ,"");
/* Read result of initialization */
Errorcode = graphresult ();
If (errorcode! = GrOk)/* an error occurred */
{
Printf ("Graphics error: % s", grapherrormsg (errorcode ));
Printf ("Press any key to halt :");
Getch ();
Exit (1);/* terminate with an error code */
}
Midx = getmaxx ()/2;
Midy = getmaxy ()/2;
/* Move the C.P. to the center of the screen */
Moveto (midx, midy );
/* Output text starting at the C.P .*/
Outtext ("This ");
Outtext ("is ");
Outtext ("");
Outtext ("test .");
/* Clean up */
Getch ();
Closegraph ();
Return 0;
}

Function Name: outtextxy
Function: display a string at a specified position
Usage: void far outtextxy (int x, int y, char * textstring );
Program example:
# Include
# Include
# Include
# Include
Int main (void)
{
/* Request auto detection */
Int gdriver = DETECT, gmode, errorcode;
Int midx, midy;
/* Initialize graphics and local variables */
Initgraph (& gdriver, & gmode ,"");
/* Read result of initialization */
Errorcode = graphresult ();
If (errorcode! = GrOk)/* an error occurred */
{
Printf ("Graphics error: % s", grapherrormsg (errorcode ));
Printf ("Press any key to halt :");
Getch ();
Exit (1);/* terminate with an error code */
}
Midx = getmaxx ()/2;
Midy = getmaxy ()/2;
/* Output text at the center of the screen */
/* Note: the C.P. doesn't get changed .*/
Outtextxy (midx, midy, "This is a test .");
/* Clean up */
Getch ();
Closegraph ();
Return 0;
}

Function Name: lock
Function: sets the File Share lock.
Usage: int lock (int handle,

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.