CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2013
    Posts
    1

    Post Help with Backward function

    Can someone please help me with my program it says there is no problem with the build but when exe. it displays a bunch of backward 'k' instead of reversing the words entered.

    Problem: Enter in a C-string and use function to display the word backward. (it might help with a pointer but im not sure how to go about it)

    lab10_p2.cpp

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Help with Backward function

    Set a break point in the begin of your display function, Press F5 to start debugging, then press F10 for each next step... and look at the debug windows ("Auto", Watch", ...) to see what happens with your variables... Then you'll be able to know what and why goes wrong.
    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Help with Backward function

    Please post the code here (with code tags) rather than providing a web link. Some of us don't open links from unknown sources so won't be able to provide guidance.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Help with Backward function

    Quote Originally Posted by 2kaud View Post
    Please post the code here (with code tags) rather than providing a web link. Some of us don't open links from unknown sources so won't be able to provide guidance.
    Well, it is not an external link... It is just the attachment to his/her post.
    However, I agree that inserting this code in the OP (with Code tags, of course!) would be much better.
    Victor Nijegorodov

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Help with Backward function

    Most of your array is just unitialized garbage. When you reverse the entire array, that's what you see. Your loop should only cover the string that was entered, not the entire buffer.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured