Usage of several C functions learned today (atexit, atoi, atof, ATOL)

Source: Internet
Author: User
Usage of several C functions learned today (atexit, atoi, atof, ATOL)
22:52:17
Function Name: atexit
Function: registers the termination function. It is called after the main function is completed;
Usage: int atexit (atexit_t func );
Program example:
# Include <stdio. h>
# Include <stdlib. h>
Void exit_fn1 (void)
{
Printf ("exit function #1 called/N ");
}
Void exit_fn2 (void)
{
Printf ("exit function #2 called/N ");
}
Int main (void)
{
/* Post exit function #1 */
Atexit (exit_fn1 );
/* Post exit function #2 */
Atexit (exit_fn2 );
Return 0;
} Function name: atoi
Function: converts a string to an integer.
Usage: int atoi (const char * nptr );
Program example:
# Include <stdlib. h>
# Include <stdio. h>
Int main (void)
{
Int N;
Char * STR = "12345.67 ";
N = atoi (STR );
Printf ("string = % s integer = % d/N", STR, N );
Return 0;
} Function name: atof
Function: converts a string to a floating point number.
Usage: Double atof (const char * nptr );
Program example:
# Include <stdlib. h>
# Include <stdio. h>
Int main (void)
{
Float F;
Char * STR = "12345.67 ";
F = atof (STR );
Printf ("string = % s float = % F/N", STR, F );
Return 0;
}

 

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.