Thread: reading input without knowing datatype

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    30

    reading input without knowing datatype

    i am supposed to read an input line (no termination condition is given hence i assume it to be '\n')
    Now the input contains of
    operands - int
    operators - char

    and i am to calculate the expression
    eg : 2 + 4

    note : i have used gets to read the whole line and store it in a char[] variable
    then in a loop i read each char from it using sscanf to process it
    but the problem is the terminating condition (the loop goes infinite if i use '\n' or '\0' )
    i have also tried concat of the string in char[] with a specific char like # and then check for it but it does not work !

    how do i do this ?
    Syra
    Amateur's urge to master C/C++

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    note : i have used gets to read the whole line and store it in a char[] variable
    You should read this FAQ entry on why you should never use gets.

    While you're at it, you should read the Announcements for suggestions on how to use this forum properly. (IE: Post some code. Use code tags when you do it.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  2. Need some help with C program writing
    By The_PC_Gamer in forum C Programming
    Replies: 9
    Last Post: 02-12-2008, 09:12 PM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Trouble with a lab
    By michael- in forum C Programming
    Replies: 18
    Last Post: 12-06-2005, 11:28 PM