Need help with Char

This is a discussion on Need help with Char within the C Programming forums, part of the General Programming Boards category; I have to make a program where the user enters 3 char characters which ends up being a number, an ...

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

    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
    Location
    segmentation fault
    Posts
    8,300
    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:
    http://206.251.36.107/programming/stdin_buffer.mhtml
    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, 07:02 AM
  2. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 08:36 AM
  3. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 10: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


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