#include <stdio.h>
#include <string.h>
#include <ctype.h>
/*
extract_parts
-------------
Splits a floating‑point number stored as a string into:
- digits before the decimal point
- digits after the decimal point
The function:
1. Uses strtok() to split on '.'
2. Filters out only digit characters from each part
3. Stores results in caller‑provided buffers
Assumes the input contains exactly one decimal point.
*/
void extract_float_digits(char *s, char *before, char *after) {
char *left = strtok(s, ".");
char *right = strtok(NULL, ".");
size_t bi = 0, ai = 0;
// Copy only digits from the left side
for (size_t i = 0; left[i] != '\0'; i++) {
if (isdigit((unsigned char)left[i])) {
before[bi++] = left[i];
}
}
before[bi] = '\0';
// Copy only digits from the right side
for (size_t i = 0; right[i] != '\0'; i++) {
if (isdigit((unsigned char)right[i])) {
after[ai++] = right[i];
}
}
after[ai] = '\0';
}
int main(void)
{
char s[] = "c/c++ c#893725.1046java python";
// Buffers large enough for digits
char before[32] = "";
char after[32] = "";
extract_float_digits(s, before, after);
printf("Before decimal: %s\n", before);
printf("After decimal: %s\n", after);
return 0;
}
/*
run:
Before decimal: 893725
After decimal: 1046
*/