String Problem

This is a discussion on String Problem within the C Programming forums, part of the General Programming Boards category; hi, ok..i'm trying to work on this function which adds any missing plus signs in front of any terms that ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    5

    Question String Problem

    hi,

    ok..i'm trying to work on this function which adds any missing plus signs in front of any terms that do not have one. The math equation is a string so basically if i have like 3w-y=5, i want to make it +3w-y=+5.

    The way i'm looking at this is that maybe i need to place a string inside another string or maybe i can check if a term doesn't begin with one(don't know how to do this), i can insert the plus sign.

    So confused
    Thanks for any help and direction

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    you cant 'insert' it. but you can concatenate two strings together or even read one string character by character into a new string.

    http://www.acm.uiuc.edu/webmonkeys/b...uide/2.14.html

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    5
    ok..i understand how to read a string into a character(thought abt that) but i''m not sure how to check if a one is present before a term...i mean like for(-z) there is implicit one there...i don't understand how to check for that either.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Break it into logical steps. How do you do it manually? How would you turn that into code?
    Code:
    look at the first portion
        does it begin with a sign?
        no - add one
        yes - read until the next "portion" is encountered
    repeat until done
    That's pretty much how you'd do it, right?
    Code:
    3w + 5x = 8w
    Look at the first portion. That would be "3w". There is no sign, so add a positive sign as the default.

    "+3w"

    Now we encountere the beginning of a new portion, signified by some form of mathmatical gizmo. In this case, it is in fact a sign. So, we grab it, along with everything until the next "mathmatical gizmo", as the next "portion".

    Repeat until done.

    "+3w" "+5x" "=" "+8w"

    That's what you were looking for right? Now you add a bit of complexity working with parenthesis and the like. It's up to you to decide what constitues a "portion", and what to do when you encounter a "mathmatical gizmo".

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

  5. #5
    Registered User
    Join Date
    Nov 2004
    Posts
    5
    i understand the logical steps required to do this, its just that i don't know how to look at portions before the math opertaor and insert the plus sign.
    The way i'm trying is to find where a plus sign is located in the string, save that location, then make a new string which adds the plus sign until the location where the plus sign is....but i don't think that right

  6. #6
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Quote Originally Posted by axe786
    i understand the logical steps required to do this, its just that i don't know how to look at portions before the math opertaor and insert the plus sign.
    then you prolly don't understand the logic. where do you want to insert the sign? before a............digit, right? so check before every digit. go back to the space you want and put the sign there. off the top, you can prlly use the isdigit() function. or you can make one up of your own.

    isdigit() info located here

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. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 02:40 AM
  4. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  5. Replies: 4
    Last Post: 03-03-2006, 01:11 AM

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