Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Clever Code
  4. String with \r in the end

String with \r in the end

Scheduled Pinned Locked Moved Clever Code
helpc++debuggingjson
14 Posts 10 Posters 13 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z zzlove

    \r is Carriage return,and it don't equal \n,so you can do this: char test[20]; strcpy(test, "abcde\r\n"); strcat(test, "*"); printf("%s\n", test);

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #5

    It was file scanning algorithm bug, which added \r to every string by mistake. It would be better to have \r\n in this bug, you are right! I my next bug I will try to do this.

    modified on Thursday, September 16, 2010 10:40 AM

    OriginalGriffO 1 Reply Last reply
    0
    • L Lost User

      char test[20];
      strcpy(test, "abcde\r");
      strcat(test, "*");
      printf("%s\n", test);

      printf prints:

      *bcde

      VC++ 2005 debugger shows:

      test "abcde*"

      And actual string is "abcde\r*". I spent two hours fighting with small file parsing error, when every string ended with \r. As usual, looks quite stupid when the problem is solved.

      modified on Monday, September 13, 2010 9:10 AM

      O Offline
      O Offline
      oggenok64
      wrote on last edited by
      #6

      Now i understand why they call it careless return :-) - turin

      1 Reply Last reply
      0
      • L Lost User

        char test[20];
        strcpy(test, "abcde\r");
        strcat(test, "*");
        printf("%s\n", test);

        printf prints:

        *bcde

        VC++ 2005 debugger shows:

        test "abcde*"

        And actual string is "abcde\r*". I spent two hours fighting with small file parsing error, when every string ended with \r. As usual, looks quite stupid when the problem is solved.

        modified on Monday, September 13, 2010 9:10 AM

        M Offline
        M Offline
        Marc Clifton
        wrote on last edited by
        #7

        Have you ever worked with an old teletype or dotmatrix printer? ;) Marc

        1 Reply Last reply
        0
        • L Lost User

          char test[20];
          strcpy(test, "abcde\r");
          strcat(test, "*");
          printf("%s\n", test);

          printf prints:

          *bcde

          VC++ 2005 debugger shows:

          test "abcde*"

          And actual string is "abcde\r*". I spent two hours fighting with small file parsing error, when every string ended with \r. As usual, looks quite stupid when the problem is solved.

          modified on Monday, September 13, 2010 9:10 AM

          B Offline
          B Offline
          buaaxiao
          wrote on last edited by
          #8

          char test[20]; strcpy(test, "abcde"); strcat(test, "*"); printf("%s\n", test); now the output is abcde* '\r' means the new line will start at the begin of the same line and the former characters will be covered off

          L 1 Reply Last reply
          0
          • B buaaxiao

            char test[20]; strcpy(test, "abcde"); strcat(test, "*"); printf("%s\n", test); now the output is abcde* '\r' means the new line will start at the begin of the same line and the former characters will be covered off

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #9

            Thanks, man, you really saved me! And your explanation is fantastic!!

            M 1 Reply Last reply
            0
            • L Lost User

              Thanks, man, you really saved me! And your explanation is fantastic!!

              M Offline
              M Offline
              Matt Gerrans
              wrote on last edited by
              #10

              \r can be nifty for updating status in place in a console tool; like showing a twirling bar, or updating percentage complete value. You can see it in something like pkzip or robocopy. Some of us are even old enough to have written code like this. :-D

              Matt Gerrans

              B 1 Reply Last reply
              0
              • L Lost User

                It was file scanning algorithm bug, which added \r to every string by mistake. It would be better to have \r\n in this bug, you are right! I my next bug I will try to do this.

                modified on Thursday, September 16, 2010 10:40 AM

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #11

                You plan your bugs in advance? Now that's organised! :laugh: Is there a form you have to fill in before you start coding a bug, or do you just wing it and publicise it later? (I used to have a Bug Request form, produced by the same secretary that issued the "Fire in the building instructions": "In case of fire, do not leave the lift.")

                Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                L 1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  You plan your bugs in advance? Now that's organised! :laugh: Is there a form you have to fill in before you start coding a bug, or do you just wing it and publicise it later? (I used to have a Bug Request form, produced by the same secretary that issued the "Fire in the building instructions": "In case of fire, do not leave the lift.")

                  Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #12

                  Some programmers don't understand what is Wicked Code forum, and explain me how to fix this bug, something like "Hey, just remove \r in the end, and everything will be fine!". I really don't know how to react to these posts, planning my bugs is kind of sarcasm. But generally, this is a good idea, planned bugs are easy to fix. Is Bug Request form available online and free for commercial use?

                  1 Reply Last reply
                  0
                  • M Matt Gerrans

                    \r can be nifty for updating status in place in a console tool; like showing a twirling bar, or updating percentage complete value. You can see it in something like pkzip or robocopy. Some of us are even old enough to have written code like this. :-D

                    Matt Gerrans

                    B Offline
                    B Offline
                    Blake Miller
                    wrote on last edited by
                    #13

                    And what is really cool is when you pipe the output from a console application like that to a text file.... X|

                    M 1 Reply Last reply
                    0
                    • B Blake Miller

                      And what is really cool is when you pipe the output from a console application like that to a text file.... X|

                      M Offline
                      M Offline
                      Matt Gerrans
                      wrote on last edited by
                      #14

                      Not a problem if the program was well written; for example robocopy has the /np option for exactly that purpose.

                      Matt Gerrans

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups