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. c++ code

c++ code

Scheduled Pinned Locked Moved C / C++ / MFC
c++
7 Posts 5 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.
  • P Offline
    P Offline
    phineas kimathi
    wrote on last edited by
    #1

    a code to change string to uppercase using integer values within the code.

    L R S 3 Replies Last reply
    0
    • P phineas kimathi

      a code to change string to uppercase using integer values within the code.

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

      There are built in library and MFC functions to perform this. Please explain what you mean by "change string to uppercase using integer values"?

      One of these days I'm going to think of a really clever signature.

      1 Reply Last reply
      0
      • P phineas kimathi

        a code to change string to uppercase using integer values within the code.

        R Offline
        R Offline
        Rajesh R Subramanian
        wrote on last edited by
        #3

        Hint: There's an offset of 32 between lower and upper cased letters. For example, the ascii value (int) of lower case 'c' is 99, and the same of upper case 'C' is 67.

        "Real men drive manual transmission" - Rajesh.

        1 Reply Last reply
        0
        • P phineas kimathi

          a code to change string to uppercase using integer values within the code.

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

          The integer difference between a lowercase char and a uppercase char when subtracted is 32. simply subtract the lowercase by 32 to get a uppercase char.

          #include #include int main(void)
          {
          char strchr[32] = "the quick fox";
          int strlength=strlen(strchr);

              printf("Before\\n" );
          printf("%s\\n\\n", strchr);
          
          for (int i=0; i\= 97) && (strchr\[i\] <= 122)) 
          	{
          		strchr\[i\] = strchr\[i\] -32;
          		
          	}
          }
              printf("After\\n" );	 
          printf("%s\\n\\n", strchr);
          

          return(0);

          }

          L D 2 Replies Last reply
          0
          • S Software_Developer

            The integer difference between a lowercase char and a uppercase char when subtracted is 32. simply subtract the lowercase by 32 to get a uppercase char.

            #include #include int main(void)
            {
            char strchr[32] = "the quick fox";
            int strlength=strlen(strchr);

                printf("Before\\n" );
            printf("%s\\n\\n", strchr);
            
            for (int i=0; i\= 97) && (strchr\[i\] <= 122)) 
            	{
            		strchr\[i\] = strchr\[i\] -32;
            		
            	}
            }
                printf("After\\n" );	 
            printf("%s\\n\\n", strchr);
            

            return(0);

            }

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

            Using hexadecimal rather than decimal integer values makes the code much more readable.

            One of these days I'm going to think of a really clever signature.

            1 Reply Last reply
            0
            • S Software_Developer

              The integer difference between a lowercase char and a uppercase char when subtracted is 32. simply subtract the lowercase by 32 to get a uppercase char.

              #include #include int main(void)
              {
              char strchr[32] = "the quick fox";
              int strlength=strlen(strchr);

                  printf("Before\\n" );
              printf("%s\\n\\n", strchr);
              
              for (int i=0; i\= 97) && (strchr\[i\] <= 122)) 
              	{
              		strchr\[i\] = strchr\[i\] -32;
              		
              	}
              }
                  printf("After\\n" );	 
              printf("%s\\n\\n", strchr);
              

              return(0);

              }

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

              TopCoder23 wrote:

              char strchr[32] = "the quick fox";

              I would consider a different variable name as strchr is the name of a CRT function.

              TopCoder23 wrote:

              if((strchr[i] >= 97) && (strchr[i] <= 122))

              What about:

              if (islower(strchr[i]))
              strchr[i] = toupper(strchr[i]);

              "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

              "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

              S 1 Reply Last reply
              0
              • D David Crow

                TopCoder23 wrote:

                char strchr[32] = "the quick fox";

                I would consider a different variable name as strchr is the name of a CRT function.

                TopCoder23 wrote:

                if((strchr[i] >= 97) && (strchr[i] <= 122))

                What about:

                if (islower(strchr[i]))
                strchr[i] = toupper(strchr[i]);

                "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

                "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

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

                You're right about strchr() . and islower(). http://www.cplusplus.com/reference/clibrary/cstring/strchr/[^]

                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