forked from portfoliocourses/c-example-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrtod.c
30 lines (26 loc) · 839 Bytes
/
strtod.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*******************************************************************************
*
* Program: strtod() Tutorial
*
* Description: Example of how to use the strtod() function in C.
*
* YouTube Lesson: https://www.youtube.com/watch?v=Kc5V2Hq4Fmc
*
* Author: Kevin Browne @ https://portfoliocourses.com
*
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char s[] = "978.45 Some text after the double value!";
double result;
char *ptr;
// converts the string in s to a double and returns it, and via
// pass-by-pointer also "returns" a pointer to the portion of the string
// after the double in this case " Some text..."
result = strtod(s, &ptr);
printf("result: %f\n", result);
printf("string: |%s|\n", ptr);
return 0;
}