Thread: C Calculator - Reading and Writing from file

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    2

    Question C Calculator - Reading and Writing from file

    Hi,
    I am trying to make a calculator that reads an input file like the example below and then outputs to another file like the example. I am trying not to use any string operations like strlen and things like that. Can someone please assist me on how to spilt up the string into it's separates operators and operands.

    Input File Example
    5*5
    Output File Example

    5*5 = 25
    Thanks
    Last edited by eddster2309; 04-09-2019 at 02:13 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,254
    Sounds good. Do it!
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2019
    Posts
    2
    Can you please assist me on how to spilt up the string into it's separates operators and operands.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,254
    I'd start by being clear on the input file format. Are you allowing for multiple digits in a number? Negative numbers? Can there be spaces between operands? What operators are permitted? Can multiple operators be used to create a more complex expression?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading and writing to the same file
    By thescratchy in forum C Programming
    Replies: 3
    Last Post: 08-05-2010, 02:02 PM
  2. reading and writing to a file
    By rocketman50 in forum C++ Programming
    Replies: 1
    Last Post: 06-15-2010, 12:36 PM
  3. reading and writing to a file
    By tikelele in forum C Programming
    Replies: 12
    Last Post: 11-26-2007, 11:37 PM
  4. File reading and writing!
    By Adamkromm in forum C++ Programming
    Replies: 9
    Last Post: 10-18-2005, 08:39 AM
  5. file writing and reading
    By Micko in forum C Programming
    Replies: 8
    Last Post: 01-13-2004, 11:18 AM

Tags for this Thread