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

String conversion example - C Tutorial

From the course: C Standard Library

Start my 1-month free trial

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…

Contents