How can i do this?Any ideas and codes will be appreciated.(I am a newbie sorry)
How can i do this?Any ideas and codes will be appreciated.(I am a newbie sorry)
Yes, simply use sprintf to print your number into a string. Then having that string, you can seperate it any way you want as each individula digit will be a character.
Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction
You might be able to do this with the localization stuff.
Check this out:
http://www.opengroup.org/onlinepubs/.../locale.h.html
Otherwise, manually, do it with sprintf() or snprintf(), which was already suggested.
nope i did not explain well.
Here is the my codes:
I don't know how can i write assort_digit func.Code:int main () { int pid; pid = getpidmap(); // now pid = 10540 or something. printf("The software running count is %d", assort_digit(pid)); // The software running count is 10.540 exit(0); } int assort_digit (int pid) { ... return pid; //this is assorting }
input: 10000 output must be: 10.000
input: 7876 output must be: 7.876
i hope you got it sorry.
Last edited by |HBO|; 08-26-2007 at 07:43 AM. Reason: typo
Same answer as what I just last said.
An int can't be formated to print a specific style. It's just an int. To the computer, a number is just a number. Commas and periods or any other punctuation are pointless and ignored.
You have to convert it to a string, because a string can be formatted since it's just text.
If this makes no sense to you, then you have to conquor the concept that a number is just a number. 1234 is 1,234 is 0000000001234 in math. The computer will see it all in binary format. It just stores each bit, it doesn't care about commas. Ask yourself how you think the computer stores a number like 5 inside RAM. Then move on to a number like 1,234. Then ask yourself how it can tell the difference between 1234 and 1,234.
I don't see what that has to do with number formatting, but 10,000 / 1000 = 10, and 7,876 / 1000 = 7.876I don't know how can i write assort_digit func.
input: 10000 output must be: 10.000
input: 7876 output must be: 7.876
i hope you got it sorry.
So assort_digit() could return whatever divided by 1000.
As for digit grouping, it depends on what sort of grouping you opt to go for as MacGyver said, see locale.h - I think 10,000 is French digit grouping or something.
Last edited by zacs7; 08-27-2007 at 12:43 AM.