1402 21 - 3/23/2010 1 COMP 1002/1402 Introduction to...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 3/23/2010 1 COMP 1002/1402 Introduction to Systems Programming Chapter 21: Function Libraries Function Libraries C has several function libraries containing pre 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 3/23/2010 2 Standard Library (stdlib.h) Contains many of the functions we have already used (malloc, free, etc). Also has some very useful conversion function: atof : converts a string to a double. ato : converts a string to an int atoi : 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...
View Full Document

This note was uploaded on 04/11/2010 for the course COMP 1402 taught by Professor Sprite during the Spring '10 term at Carleton CA.

Page1 / 8

1402 21 - 3/23/2010 1 COMP 1002/1402 Introduction to...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online