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. how to trim Spaces from unsigned char*

how to trim Spaces from unsigned char*

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
9 Posts 7 Posters 0 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.
  • U Offline
    U Offline
    User 3650979
    wrote on last edited by
    #1

    hi friends, unsigned char Cstr[100] = "this is a program"; i want remove spaces from Cstr; please help any body

    M D F 3 Replies Last reply
    0
    • U User 3650979

      hi friends, unsigned char Cstr[100] = "this is a program"; i want remove spaces from Cstr; please help any body

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Member 3653751 wrote:

      i want remove spaces from Cstr;

      So what trouble(s) are you having in doing so?

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "Man who follows car will be exhausted." - Confucius

      1 Reply Last reply
      0
      • U User 3650979

        hi friends, unsigned char Cstr[100] = "this is a program"; i want remove spaces from Cstr; please help any body

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #3

        copy the string char by char and skip the spaces.

        Watched code never compiles.

        U S 2 Replies Last reply
        0
        • M Maximilien

          copy the string char by char and skip the spaces.

          Watched code never compiles.

          U Offline
          U Offline
          User 3650979
          wrote on last edited by
          #4

          unsigned char pChar[100] = "i like vc++! "; printf("%s\n%s",pChar); it will compile and run..but it displaying 100 characters... 100 character means i like vc++ after null please help me any body

          S M C 3 Replies Last reply
          0
          • U User 3650979

            unsigned char pChar[100] = "i like vc++! "; printf("%s\n%s",pChar); it will compile and run..but it displaying 100 characters... 100 character means i like vc++ after null please help me any body

            S Offline
            S Offline
            stebich
            wrote on last edited by
            #5

            Member 3653751 wrote:

            printf("%s\n%s",pChar);

            When your format string has two %s specifiers, you must have two parameters after the format string. So add one parameter to printf() or remove one %s from format string.

            modified on Tuesday, May 4, 2010 11:35 AM

            1 Reply Last reply
            0
            • U User 3650979

              unsigned char pChar[100] = "i like vc++! "; printf("%s\n%s",pChar); it will compile and run..but it displaying 100 characters... 100 character means i like vc++ after null please help me any body

              M Offline
              M Offline
              Maximilien
              wrote on last edited by
              #6

              nothing here shows you are "trimming" the string; and there's an extra "%s" in the format part of printf.

              Watched code never compiles.

              1 Reply Last reply
              0
              • U User 3650979

                unsigned char pChar[100] = "i like vc++! "; printf("%s\n%s",pChar); it will compile and run..but it displaying 100 characters... 100 character means i like vc++ after null please help me any body

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #7

                Member 3653751 wrote:

                unsigned char pChar[100] = "i like vc++! "; printf("%s\n%s",pChar);

                Member 3653751 wrote:

                it will compile and run..but it displaying 100 characters...

                Because Visual C++ doesn't like you. :rolleyes:

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                1 Reply Last reply
                0
                • M Maximilien

                  copy the string char by char and skip the spaces.

                  Watched code never compiles.

                  S Offline
                  S Offline
                  Software_Developer
                  wrote on last edited by
                  #8

                  Hi. This litte program copys the string char by char and skips the spaces.

                  #include <iostream.h>
                  int count=0,count2=0;
                  int strLength=0;

                  int main()
                  {
                  unsigned char Cstr[100] = "this is a program";
                  unsigned char Cstr2[100] = "";

                  while(Cstr\[count\] != '\\0')
                  {
                  	  if((int)Cstr\[count\] !=32)	 
                  	  {
                  		Cstr2\[count2 \] = Cstr\[count\];
                  		  count2++;
                  	  }
                  		  
                  		count++;
                    
                    strLength++;
                  }
                  for(count=0;count<strLength;count++) cout<<Cstr2\[count\]<<"";
                  cout<<"\\n\\n\\n";
                  return 0;
                  

                  }

                  1 Reply Last reply
                  0
                  • U User 3650979

                    hi friends, unsigned char Cstr[100] = "this is a program"; i want remove spaces from Cstr; please help any body

                    F Offline
                    F Offline
                    Fareed Rizkalla
                    wrote on last edited by
                    #9

                    unsigned char Cstr[100] = "this is a program"; unsigned char CstrS[100]; for (int i = 0, i2 = 0; i < 100; i++) { if (Cstr[i] != ' ') { CstrS[i2] = Cstr[i]; i2++; } else continue; }

                    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