Results 1 to 3 of 3

Thread: read numbers from a string in C

  1. #1
    Join Date
    Aug 2012
    Beans
    2

    Question read numbers from a string in C

    I'm now writing a C program that read 2 line of strings from the screen like this:
    Code:
    2x + 3y = 1
    3x + 5y = 2
    and judge if the 2 equation is parallel or intersecting.
    I know the algorithm but i don't know how to get the coefficient from the equations.
    note that the input format may vary like 2*x + 3*y = 1.
    need help, thank you!
    Last edited by lisati; July 31st, 2013 at 07:29 PM. Reason: Formatting

  2. #2
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    1,838
    Distro
    Kubuntu 12.10 Quantal Quetzal

    Re: read numbers from a string in C

    Use regular expressions: http://stackoverflow.com/questions/1...-in-c-examples

    Regular expression would be something like

    Code:
    (\d+(\.\d+)?)\*?x\s*[+-]\s*(\d+(\.\d+)?)\*?y\s*=\s*(\d+(\.\d+)?)
    (not the full regexp to support all cases... )

  3. #3
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,297
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: read numbers from a string in C

    Also, do you really need to do this in C?
    「明後日の夕方には帰ってるからね。」


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •