#Fetch the decimal points from a string
10 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
can you be more specific
what kind of input and what kind of output do you expect
how do you want to store the numbers
as the title implies
That's not what the title implies. Not at all. The title asks how you can find a decimal point (that's the point separating the whole number from the fractional part)
how do you fetch the ASSCI numbers from a string
You don't? You already have all the ASCII values when looking at a string
;compile c
#include <stdio.h>
int main() {
// Create an example string.
char str[2048];
sprintf(str, "%f", 23.78254891);
puts("Original string:");
puts(str);
// Iterate to the demimal point or to
// the end of the string if there is none.
size_t idx = 0;
while (str[idx] != '.' &&
str[idx] != '\0')
idx++;
// Re-terminate the string to cut off the trailing digits.
// If there were none, this is a no-op.
str[idx] = '\0';
puts("Clipped string:");
puts(str);
}
Original string:
23.782549
Clipped string:
23
Since strings are null terminated, you can slap a null terminator wherever you want to clip it.
This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.