How to extract the digits of a float number before and after the point from a string in C

2 Answers

0 votes
#include <stdio.h>
#include <string.h>

int main(void)
{
    char s[] = "3.14";
    char *part;
   
    part = strtok(s, ".");
    while (part != NULL)
    {
        printf("%s\n", part);
        part = strtok(NULL, ".");
    }
    
    return 0;
}
   
/*
run:

3
14

*/

 



answered Jul 29, 2017 by avibootz
edited Jul 29, 2017 by avibootz
0 votes
#include <stdio.h>
#include <string.h>

int main(void)
{
    char s[] = "3.14";
    char *part;
   
    part = strtok(s, ".");
    printf("%s\n", part);
    part = strtok(NULL, ".");
    printf("%s\n", part);
    
    return 0;
}
   
/*
run:

3
14

*/

 



answered Jul 29, 2017 by avibootz

Related questions

...