#include
#include
#include
void addcomma( char* in, char* out );
void srev( char* in );
void main()
{
char test[100];
addcomma("1000000",test);
printf("%s\n",test);
system("pause");
}
void addcomma( char* in, char* out )
{
int len = strlen(in), i = 0;
int count = -1;
int pos = 0;
for ( i = len-1; i >= 0; i--)
{
count++;
if(count == 3)
{
out[pos] = ',';
pos++;
count = 0;
}
out[pos] = in[i];
pos++;
}
out[pos] = 0;
srev( out );
}
void srev ( char* in )
{
int len = strlen(in);
int off = 0;
char* temp = new char [ len + 10 ];
for (int i = len-1; i >= 0; i--)
{
temp[off] = in[i];
off++;
}
temp[off] = 0;
strcpy(in,temp);
delete [] temp;
}