Thread: extracting function out of a string

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    2

    extracting function out of a string

    hello all

    i write atm a little programm for my math course.
    something to determinate the min of a graph.
    i use arguments.

    the programm expecting a fuction, something like y= a*x^2+b*x +c (simple example).
    instead of x^2 i would use x*x ofc)

    now i have this function in a string, how can i calculate this math function ?
    or how do i extract it out of the string ?

    must it be a huge parser (nearly impossible, as a graph can contain many more arugments like sin/cos etc).

    is there something like a eval() function in c ??

    thx for help
    greetz
    Hellshine

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No, there is no standard function to do this for you. There have doubtless been others working on the same sort of problem, so I bet if you were to do a forum search, or even a Google search, you'd find some pointers.


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

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    2
    i have tried both, but with some keywords of the problem description i don't find anything helpful here nor in google.
    prolly with the right keywords, but i don't even know in what way a solution for this problem could look like.

    what i found out that there is no eval fuction for c
    and prolly never will be as that is a problem with all compiled languages.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Try doing a search using the words "mathematical", "expression", "parser" and "c" or something along those lines. You should get plenty of hits and possibly even some source code to look at.

    [edit]I had to do a project in college that required we write an expression parser. We had to take an expression and build a tree out of that, then we had to use that tree to differentiate that expression and display it. My skills at programming at that stage in my life were minimal and I still managed to crank something out all by myself that worked.[/edit]
    Last edited by hk_mp5kpdw; 06-15-2005 at 10:58 AM.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  3. Replies: 6
    Last Post: 04-21-2006, 08:49 PM
  4. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM