C language omit comman prob

Discussion in 'Programming' started by reinvaldez, Jan 25, 2009.

  1. #1
    hello dp,,

    programming question > how can I make this number 99,999,999,999.99 omit the comma in c language? in order for me to convert this number to word... thanks for replies... :)

    please help me.... please
     
    reinvaldez, Jan 25, 2009 IP
  2. Ancient Dragon

    Ancient Dragon Peon

    Messages:
    192
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    just erase the commas

    c++ solution:
    
    std::string num = "99,999,999,999.99";
    size_t pos;
    while( (pos = num.find(',')) != string::npos)
    {
        num.erase(pos,1);
    }
    
    Code (markup):
    c solution:
    
    int main(int argc, char** argv)
    {
    char num[] = "99,999,999,999.99";
    char* c;
    while( (c = strchr(num,',')) > 0)
    {
        memmove(c, c+1,strlen(c+1));
    }
    printf("%s\n", num);
    }
    
    Code (markup):
     
    Ancient Dragon, Jan 26, 2009 IP
  3. reinvaldez

    reinvaldez Member

    Messages:
    170
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #3
    Thank you very much sir Ancient Dragon, thanks. Sir, I have a problem about holding billions of numbers? what particular data type I can used?
     
    reinvaldez, Jan 27, 2009 IP
  4. Ancient Dragon

    Ancient Dragon Peon

    Messages:
    192
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    All data types have their limitations (maximum values). For your compiler check the header file limits.h which contains the max value for each data type. Most c and c++ compilers now support 64-bit integers which can probably hold the numbers you are using, but check limits.h.
     
    Ancient Dragon, Jan 27, 2009 IP
  5. reinvaldez

    reinvaldez Member

    Messages:
    170
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #5
    Ok I'l try it sir. Thanks. anyway sir, is their any possibilities of chopping those number by places?
     
    reinvaldez, Jan 27, 2009 IP
  6. Ancient Dragon

    Ancient Dragon Peon

    Messages:
    192
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    >>any possibilities of chopping those number by places
    You mean add the commas? Yes -- you try it yourself. And please stop calling me "sir" because I had to actually work for a living.
     
    Ancient Dragon, Jan 28, 2009 IP