Thread: A program to seperate numbers by comma

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    23

    A program to seperate numbers by comma

    I'm doing C programming.. Can I get some ideas on how to solve this question? I have totally no idea. I'm a beginner so would prefer a really simple approach (if it exist).. haha

    When writing numbers, people often follow the practice of adding commas to separate the digits in groups of 3. Example: 1234567 would be written as 1,234,567

    Given an input text file, with any kind of text, produce an output text file that’s a replica of the input file except that any occurrence of a number in the input file is replaced by the comma separated version of the same number. You may assume that every number occurrence is an integer.

  2. #2
    Registered User
    Join Date
    Dec 2008
    Posts
    32
    You asked for ideas rather than the solution, so I will offer this:

    - You can process each line by itself without consideration of the line that was before/after it, so that simplifies things. For each line:

    - Reverse the string and process it that way, then reverse it back to normal order. This way you are simply counting groups of 3 consecutive digits.

    That's one way.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-16-2009, 06:00 AM
  2. Help C program that reads Odd numbers and evens
    By Cyberman86 in forum C Programming
    Replies: 4
    Last Post: 02-27-2009, 11:59 AM
  3. somebody help me with this array program
    By hieugene in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2006, 05:53 AM
  4. C Program for Prime Numbers
    By mmuhlenb in forum C Programming
    Replies: 12
    Last Post: 02-19-2003, 04:55 AM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM