advanced scanf in c programming

This is a discussion on advanced scanf in c programming within the C Programming forums, part of the General Programming Boards category; In my C program I want a user to enter a formula, such as an equation of a line in ...

  1. #1
    Unregistered
    Guest

    Unhappy advanced scanf in c programming

    In my C program I want a user to enter a formula, such as an equation of a line in a graph. As of now I have the data entered going into an array. In every event that the user enters an "x" i want to submit a variable into. For example: If the user enters: x*x+x-2, I would like to take that input and put in different values for every time he or she entered "x". Any idea how? Or do you need more information/detail? Thanks.

  2. #2
    Registered User Strider's Avatar
    Join Date
    Aug 2001
    Posts
    149
    If all you are doing is replacing variables in an expresion, then the easiest way would be to walk through the array replacing every occurance of x with a number.
    Code:
    for (int i = 0; i < arraySize; i++)
        expression[i] = (i == 'x') ? myNumber : expression[i];
    If , however, you are building an equation and are looking for results, then you will need to go more into detail by converting the infix notation to postfix notation to adhere to the order of operation. This can get very detailed, so I am going to avoid going in to it. You can download some infix to postfix conversion examples from http://www.programmersheaven.com/zone3/cat414/16136.htm if you are interested.

    David
    Last edited by Strider; 12-07-2001 at 06:47 AM.
    One Ring to rule them all, One Ring to find them,
    One Ring to bring them all and in the darkness bind them
    In the Land of Mordor where the Shadows lie.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf() consideres useless
    By Snafuist in forum C Programming
    Replies: 15
    Last Post: 02-18-2009, 07:35 AM
  2. Help with a basic scanf procedure.
    By killpoppop in forum C Programming
    Replies: 9
    Last Post: 11-03-2008, 03:39 PM
  3. Replies: 2
    Last Post: 02-20-2005, 12:48 PM
  4. Scanf and integer...
    By penny in forum C Programming
    Replies: 3
    Last Post: 04-24-2003, 06:36 AM
  5. scanf - data is "put back" - screws up next scanf
    By voltson in forum C Programming
    Replies: 10
    Last Post: 10-14-2002, 04:34 AM

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