Thread: Need help with Char

  1. #1
    Registered User
    Join Date
    Oct 2009

    Question Need help with Char

    I have to make a program where the user enters 3 char characters which ends up being a number, an operator, and another number. (ex. 5,+,6)

    The 5 and 6 are char numbers. How do I add them together? or convert them into int?

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    Here's some commands you may want to look up and learn for this:
    • fgets
    • sscanf
    • strtol (or atoi)
    • switch

    Look at the bottom of this page:
    where I give an example of a "foolproof" function for getting a single number. You can modify that to do what you want.

    You can use switch to evaluate the arithmetic operation, eg, "case (+), case(-)" etc.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 07:36 AM
  3. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 09:22 AM
  4. Passing structures... I can't get it right.
    By j0hnb in forum C Programming
    Replies: 6
    Last Post: 01-26-2003, 11:55 AM
  5. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM

Tags for this Thread