Given a string that has a number such as:
6000 or 10000
I want to add ',' to the value so it reads
6,000 or 10,000
would be good up to about million or so. Thank you.
Given a string that has a number such as:
6000 or 10000
I want to add ',' to the value so it reads
6,000 or 10,000
would be good up to about million or so. Thank you.
Ok so what have you done so far? Show us some code or where your stuck and we will try to point you in the right direction, but no one will do the work for you and just hand it over to you.
When no one helps you out. Call google();
This has been asked and answered before. A forum search for "commaize" would find you at least one example in C and one and C++.
My best code is written with the delete key.
I'm new to C and This what I have so far in my function:
Code:char string[20]; char new[20]; sprintf(string,"%d",total); int len = strlen(string); int cnt = 0; for(int i = len; string[i] != NULL; i--) { strcpy(new[i],string[]; cnt++; if(cnt == 3) { i += 1; stncpy(new[i],","); } }
I searched the forums, I only found one for C++ but no references to C.
off the top of my head, what you would need to do is copy characters to a new string, backwards, one at a time. Every three characters, insert a ',' and then continue copying from the original string. The i suppose you need to reverse the characters around again...
>I searched the forums, I only found one for C++ but no references to C.
I gave you a search string to use, that means I know that the code is there (since I wrote it). You'll need to read a bit though, it's not right at the top with big flashing letters that say "FOR CISOKAY".
My best code is written with the delete key.