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. General Programming
  3. C / C++ / MFC
  4. Non Printing Characters

Non Printing Characters

Scheduled Pinned Locked Moved C / C++ / MFC
help
8 Posts 3 Posters 2 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.
  • J Offline
    J Offline
    John Bosko
    wrote on last edited by
    #1

    :((Hi, I've got a code which is adding 2 non-printable characters at the end of the string, which is causing a lot of problem. Can anyone help me in removing these 2 "funny" characters. Here is the code [CODE] ======================================== #include #include #include #include #include using std::string; const char *yy; int u,i; string final = "888808M5359846\n"; void main() { final.append("02/10/2002 14:30:10\n"); yy=final.c_str(); u=strlen(yy); for(i=0;i<=u;i++) { printf("%c %d\n",yy[i],yy[i]); } } =========================================== [CODE] Kindly help!! Many Thanks, John

    D 1 Reply Last reply
    0
    • J John Bosko

      :((Hi, I've got a code which is adding 2 non-printable characters at the end of the string, which is causing a lot of problem. Can anyone help me in removing these 2 "funny" characters. Here is the code [CODE] ======================================== #include #include #include #include #include using std::string; const char *yy; int u,i; string final = "888808M5359846\n"; void main() { final.append("02/10/2002 14:30:10\n"); yy=final.c_str(); u=strlen(yy); for(i=0;i<=u;i++) { printf("%c %d\n",yy[i],yy[i]); } } =========================================== [CODE] Kindly help!! Many Thanks, John

      D Offline
      D Offline
      Dominik Reichl
      wrote on last edited by
      #2

      Hello, simply replace for(i=0;i<=u;i++) by for(i=0;i<u;i++) So, remove the =. Then the 2 "funny" characters should not occur. :-D -Dominik

      J 1 Reply Last reply
      0
      • D Dominik Reichl

        Hello, simply replace for(i=0;i<=u;i++) by for(i=0;i<u;i++) So, remove the =. Then the 2 "funny" characters should not occur. :-D -Dominik

        J Offline
        J Offline
        John Bosko
        wrote on last edited by
        #3

        Hi Domnik, I did that and its not removed the second character. What comes towards the end is 10 and 0. When I do a for(i=0;i

        J D 3 Replies Last reply
        0
        • J John Bosko

          Hi Domnik, I did that and its not removed the second character. What comes towards the end is 10 and 0. When I do a for(i=0;i

          J Offline
          J Offline
          jhwurmbach
          wrote on last edited by
          #4

          You mean the number representation of the linefeed-character? Well, you could count two less than the string-length (CR/LF), or you could introduce a filtering line, that does skip any LF characters. That way you would even skip internal CR/LF sequences. "My opinions may have changed, but not the fact that I am right." Found in the sig of Herbert Kaminski

          1 Reply Last reply
          0
          • J John Bosko

            Hi Domnik, I did that and its not removed the second character. What comes towards the end is 10 and 0. When I do a for(i=0;i

            J Offline
            J Offline
            jhwurmbach
            wrote on last edited by
            #5

            By the way: C++ like would be doing that with iterators. Its just as easy and less error prone. (see your index error dominic has shown) "My opinions may have changed, but not the fact that I am right." Found in the sig of Herbert Kaminski

            1 Reply Last reply
            0
            • J John Bosko

              Hi Domnik, I did that and its not removed the second character. What comes towards the end is 10 and 0. When I do a for(i=0;i

              D Offline
              D Offline
              Dominik Reichl
              wrote on last edited by
              #6

              As jh pointed out, you have to change the u to u=strlen(yy) - 2; when using CR/LF (\r\n) and u=strlen(yy) - 1; when using LF only (only \n).

              J 1 Reply Last reply
              0
              • D Dominik Reichl

                As jh pointed out, you have to change the u to u=strlen(yy) - 2; when using CR/LF (\r\n) and u=strlen(yy) - 1; when using LF only (only \n).

                J Offline
                J Offline
                John Bosko
                wrote on last edited by
                #7

                Hi Dominik and Jh, Yes, your suggestions worked out. Apparently the problem still persists and I've got no clue why its happening.. What I am doing is just sending in some data to another server using a sendto(). The server program is written in Java. But when I send it, the server gets it with some non-printing character (ASCII '0') in the begining and it's causing a problem. Any suggestions, what could be going wrong? Here's the sendto() code [CODE] ======================================== e = sendto(sd,final.c_str(),final.length(),0,(struct sockaddr *)&saServer,sizeof(saServer)); ======================================== [CODE] Many Thanks, John:((

                J 1 Reply Last reply
                0
                • J John Bosko

                  Hi Dominik and Jh, Yes, your suggestions worked out. Apparently the problem still persists and I've got no clue why its happening.. What I am doing is just sending in some data to another server using a sendto(). The server program is written in Java. But when I send it, the server gets it with some non-printing character (ASCII '0') in the begining and it's causing a problem. Any suggestions, what could be going wrong? Here's the sendto() code [CODE] ======================================== e = sendto(sd,final.c_str(),final.length(),0,(struct sockaddr *)&saServer,sizeof(saServer)); ======================================== [CODE] Many Thanks, John:((

                  J Offline
                  J Offline
                  John Bosko
                  wrote on last edited by
                  #8

                  Hi Dominik and Jh, Just out of curiosity, can we do something like concatenating 2 strings? Something like this in sendto()? ======================== e = sendto(sd,"string1"+"string2",lenght(),0,(struct sockaddr *)&saServer,sizeof(saServer)); ======================== Many Thanks, John

                  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