C Programming Question

This is a discussion on C Programming Question within the C Programming forums, part of the General Programming Boards category; How do I both allow a user to input some formula such as X + 1 then allow myself to ...

  1. #1
    Unregistered
    Guest

    C Programming Question

    How do I both allow a user to input some formula such as X + 1 then allow myself to use that formula to produce some output such as x = 3; 3+1 =4; output: 4?

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    88
    Uh, that's nat that simple!

    You have to write a parser on your own. In the book "C++ Complete Reference", Herbert Schildt discribes how to write such a parser...
    Hope you don't mind my bad english, I'm Austrian!

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Are you the same one who's posted this question 3 times already? Do something like the following to parse the string entered by the user then use your favorite switch statement to do the calculation.
    Code:
    int main(){
    	char array[] = "x+x*3", *p = &array[0];
    	char y = '5';
    
    	while(*p != '\0'){
    		if(*p == 'x')
    			*p = y;
    		p++;
    	}
    
    	puts(array);
    
    	return 0;
    }
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 03:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

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