Comma's and decimal input

Question: Well I have to input a number correctly with comma's and a decimal. My input would be 243,111.11 and the output would come out as 2,43,,111.11
Do I have to create additional for loops statements for each digits and check for comma's/decimal? I almost scrapped this code for attempting to try switch statement. All I just need is advice/tips.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>

int main() {
	using namespace std;
	
    char myStr[256];    
    cout << "Enter Any integers ";
	cin.getline(myStr,256);

 
    int numDigits = strchr(myStr, '.') - myStr;
    int i, distance;
 
    for(i=0; myStr[i] != '\0'; i++) {
        putchar(myStr[i]);
        distance = numDigits - i - 1;
        if(distance > 0 && distance%3 == 0) putchar(',');
	
    }
 
    return 0;
}
Topic archived. No new replies allowed.