Thread: processing input file

  1. #1
    Registered User
    Join Date
    May 2008

    processing input file

    Suppose I have an input file:

    34, 53, 45, 87, 76, 39
    24, 78, 54, 98
    after each line I want to print the sum of all integers in the line? how to do that?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Read a whole line using getline()
    Parse the line, looking for numbers and commas.

    The parsing could be done any number of ways.
    First you should decide whether to use a char array or a std::string.

    If you at least try something, we can push you along when you get stuck.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fscanf in different functions for the same file
    By bchan90 in forum C Programming
    Replies: 5
    Last Post: 12-03-2008, 09:31 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM