Project

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • d0ugg
    New Member
    • Jan 2007
    • 41

    #1

    Project

    Hi,

    I wrote a palindrome code in C++, and got a few errors that I can not figure it out. I'm suppose to write the palindrome program and "erase the spaces betweeen words".
    Code:
    *snip*
    The line in bold is the problem,

    Thanks,

    Doug
    Last edited by RedSon; Mar 28 '07, 02:40 PM. Reason: Code deleted per homework policy
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    There were four or fives lines bolded, can you post the one that you think is the problem, and how you know it's the problem (ie - the error message, or a description of what the output is doing that is incorrect)?

    Comment

    • RedSon
      Recognized Expert Expert
      • Jan 2007
      • 4980

      #3
      If this is a homework question it should be treated as such. Is this palindrome code part of your assignment?

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        Also dougg your thread title is unacceptable per the posting guidelines. Please read the FAQ located in the Tabs above and pay particular attention to http://www.thescripts.com/forum/faq....d_thread_title

        Comment

        • d0ugg
          New Member
          • Jan 2007
          • 41

          #5
          Sorry for the title.
          This is part of my hw, but i already included the code. I just need to know what is the error. I forgot to include the error message;
          Here it goes:

          c:\documentos\p rogramas\palind rome\palindrome \palindrome\pal indrome.cpp(77) : error C2228: left of '.length' must have class/struct/union
          c:\documentos\p rogramas\palind rome\palindrome \palindrome\pal indrome.cpp(78) : error C2109: subscript requires array or pointer type
          c:\documentos\p rogramas\palind rome\palindrome \palindrome\pal indrome.cpp(79) : error C2228: left of '.erase' must have class/struct/union

          So those are the error messages, and here are the lines:

          for (int i = 0; i < s.length(); i++)
          if (s[i] == ' ')
          s.erase(i, 1);

          Thanks again

          Comment

          • RedSon
            Recognized Expert Expert
            • Jan 2007
            • 4980

            #6
            No problem its just a warning so that you will be better prepared for the future. Also, please read the posting guidelines in the FAQ, for homework assignments we limit code to just the lines that are causing the problem. What you have copied above is fine.

            Comment

            • RedSon
              Recognized Expert Expert
              • Jan 2007
              • 4980

              #7
              Originally posted by d0ugg
              Sorry for the title.
              This is part of my hw, but i already included the code. I just need to know what is the error. I forgot to include the error message;
              Here it goes:

              c:\documentos\p rogramas\palind rome\palindrome \palindrome\pal indrome.cpp(77) : error C2228: left of '.length' must have class/struct/union
              c:\documentos\p rogramas\palind rome\palindrome \palindrome\pal indrome.cpp(78) : error C2109: subscript requires array or pointer type
              c:\documentos\p rogramas\palind rome\palindrome \palindrome\pal indrome.cpp(79) : error C2228: left of '.erase' must have class/struct/union

              So those are the error messages, and here are the lines:

              for (int i = 0; i < s.length(); i++)
              if (s[i] == ' ')
              s.erase(i, 1);

              Thanks again
              Please give us the declaration for what s is. If its String s, then it should be String s = new String(); before you can start doing operations on it.

              Comment

              • sicarie
                Recognized Expert Specialist
                • Nov 2006
                • 4677

                #8
                s was declared int.

                Comment

                • d0ugg
                  New Member
                  • Jan 2007
                  • 41

                  #9
                  s = space between words.

                  please let me know if you have any other question

                  doug

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    Originally posted by RedSon
                    No problem its just a warning
                    The compiler clearly did say "error" instead of "waring" in its diagnostic message
                    though.

                    kind regards,

                    Jos

                    ps. not surprising because that 's' identifier was defined to be of type int.

                    Comment

                    • RedSon
                      Recognized Expert Expert
                      • Jan 2007
                      • 4980

                      #11
                      Originally posted by JosAH
                      The compiler clearly did say "error" instead of "waring" in its diagnostic message
                      though.

                      kind regards,

                      Jos

                      ps. not surprising because that 's' identifier was defined to be of type int.
                      Either you are trying to make a joke or you misunderstand me. I wasn't referring to the compiler problems.

                      Comment

                      • RedSon
                        Recognized Expert Expert
                        • Jan 2007
                        • 4980

                        #12
                        Originally posted by sicarie
                        s was declared int.
                        if s is an int you cannot do things like s.length or s[i] those are undefined for type int.

                        Comment

                        Working...