{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

1402 21

# 1402 21 - COMP1002/1402 Chapter21:FunctionLibraries...

This preview shows pages 1–4. Sign up to view the full content.

3/23/2010 1 COMP 1002/1402 Introduction to Systems Programming Chapter 21: Function Libraries Function Libraries C has several function libraries containing pre d fi d f ti defined functions we can use. Standard I/O (stdio.h) Standard library (stdlib.h) Type library (ctype.h) Math library (math.h) COMP1002/1402 - Chapter 21: Function Libraries 2

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
3/23/2010 2 Standard Library (stdlib.h) Contains many of the functions we have l d d ( ll f t ) already used (malloc, free, etc). Also has some very useful conversion function: atof : converts a string to a double. atoi : converts a string to an int : converts a string to an int. atol : converts a string to an long. COMP1002/1402 - Chapter 21: Function Libraries 3 atoi() example #include <stdio.h> #include <stdlib.h> int main() { char str1[] = "124z3yu87"; char str2[] = "-3.4"; char *str3 = "e24"; printf("str1: %d\n", atoi (str1)); printf("str2: %d\n", atoi (str2)); printf("str3: %d\n", atoi (str3)); return 0; } COMP1002/1402 - Chapter 21: Function Libraries 4
3/23/2010 3 More stdlib.h conversions strtod : string to double strtof : string to float strtol : string to long strtold : string to long double COMP1002/1402 - Chapter 21: Function Libraries 5 strtod() Function Takes as many characters as possible that are valid following a syntax resembling that of floating point literals, and interprets them as a numerical value.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.