From the course: C Standard Library
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
String conversion example - C Tutorial
From the course: C Standard Library
String conversion example
- [Instructor] Now let's see these functions in an example. This example has three parts. In the first one, we'll see atoi, as you can see in the comments. In the second one, we'll see STR to long, and in the third one, sscanf. So let's get started with atoi. As you can see in line six, we have str1, which is a string that contains a representation for the number 572. So if I want to convert that string to a number, I can use atoi, so let me do that in line seven. I will assign to a new integer value that's called an X the return value of atoi, with an argument of str1. That's it. So that's the beauty of atoi. It's very simple to use. Now let's print it out. Let me say X equals this value, and the variable will be X. That's it for part one. Now let's get to part two, where we will use STR to long. Now, if you look at the string in line 11, you'll see that str2 has two numbers. The first one is a decimal number 123, that's what I meant by it, and the second one is a hexadecimal number…
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
-
(Locked)
Memory allocation example2m 29s
-
(Locked)
Random number generation1m 48s
-
(Locked)
Random number generation example2m 40s
-
(Locked)
String conversion2m 11s
-
(Locked)
String conversion example6m 29s
-
(Locked)
Sort and search1m 52s
-
(Locked)
Sort and search main4m 50s
-
(Locked)
Sort and search functions5m 6s
-
(Locked)
Challenge: Let's get random1m 38s
-
(Locked)
Solution: Let's get random5m 40s
-
-
-
-