processing input file

This is a discussion on processing input file within the C++ Programming forums, part of the General Programming Boards category; Suppose I have an input file: Code: 34, 53, 45, 87, 76, 39 24, 78, 54, 98 ..... after each ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    134

    processing input file

    Suppose I have an input file:

    Code:
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,336
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 08: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21