C language library function (G-type letters)

Source: Internet
Author: User

Function Name: getdate
Power: DOS date
Usage: void getdate (strUCt * dateblk );
Program example:
# Include <dos. h>
# Include <stdio. h>
Int main (void)
{
Struct date d;
Getdate (& d );
PRintf ("The current year is: % d ",
D. da_year );
Printf ("The current day is: % d ",
D. da_day );
Printf ("The current month is: % d ",
D. da_mon );
Return 0;
}
Function Name: getdefapalpalette
Function: return the definition structure of the color palette.
Usage: struct palettetype * far getdefapalpalette (void );
Program example:
# Include <graphics. h>
# Include <stdlib. h>
# Include <stdio. h>
# Include <conio. h>
Int main (void)
{
/* Request auto detection */
Int gdriver = DETECT, gmode, errorcode;
Int I;
/* Structure for returning palette copy */
Struct palettetype far * pal = (void *) 0;
/* 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 ();
/* Terminate with an error code */
Exit (1 );
}
Setcolor (getmaxcolor ());
/* Return a pointer to the default palette */
Pal = getdefapalpalette ();
For (I = 0; I <16; I ++)
{
Printf ("colors [% d] = % d", I,
Pal-> colors [I]);
Getch ();
}
/* Clean up */
Getch ();
Closegraph ();
Return 0;
}
Function Name: getdisk
Function: obtains the drive letter of the current disk.
Usage: int getdisk (void );
Program example:
# Include <stdio. h>
# Include <dir. h>
Int main (void)
{
Int disk;
Disk = getdisk () +;
Printf ("The current drive is: % c ",
Disk );
Return 0;
}
Function Name: getdrivername
Function: returns a string pointer to the name of the current graphic driver.
Usage: char * getdrivename (void );
Program example:
# Include <graphics. h>
# Include <stdlib. h>
# Include <stdio. h>
# Include <conio. h>
Int main (void)
{
/* Request auto detection */
Int gdriver = DETECT, gmode, errorcode;
/* Stores the device driver name */
Char * drivername;
/* 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 ();
/* Terminate with an error code */
Exit (1 );
}
Setcolor (getmaxcolor ());
/* Get name of the device driver in use */
Drivername = getdrivername ();
/* For centering text on the screen */
Settextjustify (CENTER_TEXT, CENTER_TEXT );
/* Output the name of the driver */
Outtextxy (getmaxx ()/2, getmaxy ()/2,
Drivername );
/* Clean up */
Getch ();
Closegraph ();
Return 0;
}
Function Name: getdta
Function: obtains the disk transfer address.
Usage: char far * getdta (void );
Program example:
# Include <dos. h>
# Include <stdio. h>
Int main (void)
{
Char far * dta;
Dta = getdta ();
Printf ("The current disk transfer
Address is: % Fp ", dta );
Return 0;
}
Function Name: getenv
Function: Retrieves a string from the environment.
Usage: char * getenv (char * envvar );
Program example:
# Include <stdlib. h>
# Include <stdio. h>
Int main (void)
{
Char * s;
S = getenv ("COMSPEC");/* get the comspec environment parameter */
Printf ("Command processor: % s", s);/* display comspec parameter */
Return 0;
}
Function Name: getfat, getfatd
Function: obtains information about the file allocation table.
Usage: void getfat (int drive, struct fatinfo * fatblkp );
Program example:
# Include <stdio. h>
# Include <dos. h>
Int main (void)
{
Struct fatinfo diSKINfo;
Int flag = 0;
Printf ("Please insert disk in drive ");
Getchar ();
Getfat (1, & diskinfo );
/* Get drive information */
Printf ("Drive A: is ");
Switch (unsigned char) diskinfo. fi_fatid)
{
Case 0xFD:
Printf ("360 K low density ");
Break;
Case 0xF9:
Printf ("1.2 Meg high density ");
Break;
Default:
Printf ("unformatted ");
Flag = 1;
}
If (! Flag)
{
Printf ("sectors per cluster % 5d ",
Diskinfo. fi_sclus );
Printf ("number of clusters % 5d ",
Diskinfo. fi_nclus );
Printf ("bytes per sector % 5d ",
Diskinfo. fi_bysec );
}
Return 0;
}
Function Name: getfillpattern
Function: copy the User-Defined fill mode to the memory.
Usage: void far getfillpattern (char far * upattern );
Program example:
# Include <graphics. h>
# Include <stdlib. h>
# Include <stdio. h>
# Include <conio. h>
Int main (void)
{
/* Request auto detection */
Int gdriver = DETECT, gmode, errorcode;
Int maxx, maxy;
Char pattern [8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04 };
/* 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 */
}
Maxx = getmaxx ();
Maxy = getmaxy ();
Setcolor (getmaxcolor ());
/* Select a user defined fill pattern */
Setfillpattern (pattern, getmaxcolor ());
/* Fill the screen with the pattern */
Bar (0, 0, maxx, maxy );
Getch ();
/* Get the current user defined fill pattern */
Getfillpattern (pattern );
/* Alter the pattern we grabbed */
Pattern [4]-= 1;
Pattern [5]-= 3;
Pattern [6] + = 3;
Pattern [7]-= 4;
/* Select our new pattern */
Setfillpattern (pattern, getmaxcolor ());
/* Fill the screen with the new pattern */
Bar (0, 0, maxx, maxy );
/* Clean up */
Getch ();
Closegraph ();
Return 0;
}
Function Name: getfillsettings
Function: obtains information about the current fill mode and fill color.
Usage: void far getfillsettings (struct fillsettingstype far * fillinfo );
Program example:
# Include <graphics. h>
# Include <stdlib. h>
# Include <stdio. h>
# Include <conio. h>
/The names of the fill styles supported */
Char * fname [] = {"EMPTY_FILL ",
"SOLID_FILL ",
"LINE_FILL ",
"LTSLASH_FILL ",
"SLASH_FILL ",
"BKSLASH_FILL ",
"LTBKSLASH_FILL ",
"HATCH_FILL ",
"XHATCH_FILL ",
"INTERLEAVE_FILL ",
"WIDE_DOT_FILL ",
"CLOSE_DOT_FILL ",
"USER_FILL"
};
Int main (void)
{
/* Request auto detection */
Int gdriver = DETECT, gmode, errorcode;
Struct fillsettingstype fillinfo;
Int midx, midy;
Char patstr [40], colstr [40];
/* 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;
/* Get information about current fill pattern and color */
Getfillsettings (& fillinfo );
/* Convert fill information into strings */
Sprintf (patstr, "% s is the fill style.", fname [fillinfo. pattern]);
Sprintf (colstr, "% d is the fill color.", fillinfo. color );
/* Display the information */
Settextjustify (CENTER_TEXT, CENTER_TEXT );
Outtextxy (midx, midy, patstr );
Outtextxy (midx, midy + 2 * textheight ("W"), colstr );
/* Clean up */
Getch ();
Closegraph ();
Return 0;
}

Function Name: getftime
Function: Obtain the date and time of the file.
Usage: int getftime (int handle, struct ftime * ftimep );
Program example:
# Include <stdio. h>
# Include <io. h>
Int main (void)
{
FILE * stream;
Struct ftime ft;
If (stream = fopen ("TEST. $ ",
"Wt") = NULL)
{
Fprintf (stderr,
"Cannot open output file .");
Return 1;
}
Getftime (fileno (stream), & ft );
Printf ("File time: % u ",
Ft. ft_hour, ft. ft_min,
Ft. ft_tsec * 2 );
Printf ("File date: % u/% u ",
Ft. ft_month, ft. ft_day,
Ft. ft_year + 1980 );
Fclose (stream );
Return 0;
}
Function Name: getgraphmode
Function: returns the current graphic mode.
Usage: int far getgraphmode (void );
Program example:
# Include <graphics. h>
# Include <stdlib. h>
# Include <stdio. h>
# Include <conio. h>
Int main (void)
{
/* Request auto detection */
Int gdriver = DETECT, gmode, errorcode;
Int midx, midy, mode;
Char numname [80], modename [80];
/* 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 ();
/* Terminate with an error code */
Exit (1 );
}
Midx = getmaxx ()/2;
Midy = getmaxy ()/2;
/* Get mode number and name strings */
Mode = getgraphmode ();
Sprintf (numname,
"% D is the current mode number .",
Mode );
Sprintf (modename,
"% S is the current graphics mode ",
Getmodename (mode ));
/* Display the information */
Settextjustify (CENTER_TEXT, CENTER_TEXT );
Outtextxy (midx, midy, numname );
Outtextxy (midx, midy + 2 * textheight ("W "),
Modename );
/* Clean up */
Getch ();
Closegraph ();
Return 0;
}
Function Name: getftime
Function: Obtain the date and time of the file.
Usage: int getftime (int handle, struct ftime * ftimep );
Program example:
# Include <stdio. h>
# Include <io. h>
Int main (void)
{
FILE * stream;
Struct ftime ft;
If (stream = fopen ("TEST. $ ",
"Wt") = NULL)
{
Fprintf (stderr,
"Cannot open output file .");
Return 1;
}
Getftime (fileno (stream), & ft );
Printf ("File time: % u ",
Ft. ft_hour, ft. ft_min,
Ft. ft_tsec * 2 );
Printf ("File date: % u/% u ",
Ft. ft_month, ft. ft_day,
Ft. ft_year + 1980 );
Fclose (stream );
Return 0;
}

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.