Reversing String Data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #16
    Originally posted by nholdzkie
    I just made this algorithm

    1. input a character string call it word
    2. set the first character of string as index 0,
    3. set the second character as index 1
    and third is index 2 and so on until the last character of the string call it index n.
    4. then display the character string from index n until index 0

    I think we should use for loop for this code which is impossible for me to code without using function.
    This is depending on the declared type, but you could also use the strlen() function to get the length first off. Using that as your index, you could do a strlen() - (your loop increment).

    Do you think that's enough to write pseudocode on, or are you at all confused with the algorithm?

    Comment

    • nholdzkie
      New Member
      • Aug 2007
      • 10

      #17
      I haven't try writing an algorithms first before coding in my experience i use to code first before making algorithm and psuedocode.

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #18
        Originally posted by nholdzkie
        I haven't try writing an algorithms first before coding in my experience i use to code first before making algorithm and psuedocode.
        A lot of the time it's easier to get the algorithm set down - then you can get it all in your head how everything will work and function, and then it makes coding it much MUCH easier.

        If that algorithm doesn't make sense we can flesh it out a bit more, but if it does, we can hit the pseudocode, and that can be almost directly translated into code. At least, that's the way I develop...

        Comment

        • nholdzkie
          New Member
          • Aug 2007
          • 10

          #19
          well my teacher told me also to be that way the proper programmers would be

          Comment

          • nholdzkie
            New Member
            • Aug 2007
            • 10

            #20
            can i ask what is the syntax for strlen( )?? when i declare it as char *word how do i use it in cin>>??

            Comment

            • sicarie
              Recognized Expert Specialist
              • Nov 2006
              • 4677

              #21
              Originally posted by nholdzkie
              can i ask what is the syntax for strlen( )?? when i declare it as char *word how do i use it in cin>>??
              This is cplusplus.com's page on strlen() - it's a pretty good reference, usually has examples, and it's got the string.h lib to the right (the library you need to use it), so you can look through other methods that might be useful too.

              Comment

              Working...