From the course: C Standard Library
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
String conversion
- [Instructor] Stdlib provides a family of string-to-number converter functions. Some are very simple and quick. Some are very elaborate and slow. Let's start with the simplest, atoi, meaning ASCII to integer, which takes in a string containing an integer number in base 10 or decimal and returns that integer number. Next, we have atof, for ASCII to floating point, which takes in a string containing a floating point number and returns a double with that value. These two functions don't run many important checks on the content of the string, so they are not very robust. Next, we have strtol, which stands for string to long. This one works on a string containing a series of integer numbers, not just one, all separated by white space characters. That's new line, space, tab and a few more. The function receives a string str, a pointer to a string str_end and an integer representing the base of the number, decimal, hexadecimal and so on. So it works like this. The string is traversed…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Memory allocation1m 32s
-
Memory allocation example2m 29s
-
Random number generation1m 48s
-
Random number generation example2m 40s
-
String conversion2m 11s
-
String conversion example6m 29s
-
Sort and search1m 52s
-
Sort and search main4m 50s
-
Sort and search functions5m 6s
-
Challenge: Let's get random1m 38s
-
Solution: Let's get random5m 40s
-
-
-
-