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. Convert to ASCII ?

Convert to ASCII ?

Scheduled Pinned Locked Moved C / C++ / MFC
questionlounge
7 Posts 4 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.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    This seems very silly and basic - The function description is pretty clear Convert an unsigned long integer into a string, using a given base So why I keep printing numbers and NOT ASCII letter? I need a pointer to string - not numeric value. And I am sorry to ask such stupid question. Cheers Vaclav

    int base = 10;
    long value = 73;
    char buffer[33];
    unsigned long RANDOM = random(65, 79);

    for( base = 2; base <= 16; base = base + 2 ) {
        printf( "%2d %s\\n", base,
            ultoa( RANDOM, buffer, base ) );
    }
    
    CPalliniC L Richard Andrew x64R 3 Replies Last reply
    0
    • V Vaclav_

      This seems very silly and basic - The function description is pretty clear Convert an unsigned long integer into a string, using a given base So why I keep printing numbers and NOT ASCII letter? I need a pointer to string - not numeric value. And I am sorry to ask such stupid question. Cheers Vaclav

      int base = 10;
      long value = 73;
      char buffer[33];
      unsigned long RANDOM = random(65, 79);

      for( base = 2; base <= 16; base = base + 2 ) {
          printf( "%2d %s\\n", base,
              ultoa( RANDOM, buffer, base ) );
      }
      
      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      I suppose, you know that

      printf("%d\n", ul);

      and

      printf("%s\n", ultoa(ul, buffer, 10));

      should produce the same output.

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • V Vaclav_

        This seems very silly and basic - The function description is pretty clear Convert an unsigned long integer into a string, using a given base So why I keep printing numbers and NOT ASCII letter? I need a pointer to string - not numeric value. And I am sorry to ask such stupid question. Cheers Vaclav

        int base = 10;
        long value = 73;
        char buffer[33];
        unsigned long RANDOM = random(65, 79);

        for( base = 2; base <= 16; base = base + 2 ) {
            printf( "%2d %s\\n", base,
                ultoa( RANDOM, buffer, base ) );
        }
        
        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Vaclav_Sal wrote:

        So why I keep printing numbers

        Because that is what ultoa creates. It takes a numeric value (long) and converts it to printable characters. Try an input value of 127 instead of RANDOM.

        V 1 Reply Last reply
        0
        • V Vaclav_

          This seems very silly and basic - The function description is pretty clear Convert an unsigned long integer into a string, using a given base So why I keep printing numbers and NOT ASCII letter? I need a pointer to string - not numeric value. And I am sorry to ask such stupid question. Cheers Vaclav

          int base = 10;
          long value = 73;
          char buffer[33];
          unsigned long RANDOM = random(65, 79);

          for( base = 2; base <= 16; base = base + 2 ) {
              printf( "%2d %s\\n", base,
                  ultoa( RANDOM, buffer, base ) );
          }
          
          Richard Andrew x64R Offline
          Richard Andrew x64R Offline
          Richard Andrew x64
          wrote on last edited by
          #4

          Try this:

           for( base = 2; base <= 16; base = base + 2 ) {
                  ultoa( RANDOM, buffer, base );
                  printf( "%2d %s\\n", base, buffer );
           }
          

          The difficult we do right away... ...the impossible takes slightly longer.

          1 Reply Last reply
          0
          • L Lost User

            Vaclav_Sal wrote:

            So why I keep printing numbers

            Because that is what ultoa creates. It takes a numeric value (long) and converts it to printable characters. Try an input value of 127 instead of RANDOM.

            V Offline
            V Offline
            Vaclav_
            wrote on last edited by
            #5

            So itoa is really NOT "integer to ASCII" conversion, right? I knew it was a silly question. I suppose I can use some kind of lookup method the get from random index # to character array of alphabet. I'll check stdio. Thanks

            L CPalliniC 2 Replies Last reply
            0
            • V Vaclav_

              So itoa is really NOT "integer to ASCII" conversion, right? I knew it was a silly question. I suppose I can use some kind of lookup method the get from random index # to character array of alphabet. I'll check stdio. Thanks

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

              Vaclav_Sal wrote:

              So itoa is really NOT "integer to ASCII" conversion, right?

              Yes, of course it is. It converts a binary integer to a set of printable (ASCII) characters. What else would you expect it to do?

              1 Reply Last reply
              0
              • V Vaclav_

                So itoa is really NOT "integer to ASCII" conversion, right? I knew it was a silly question. I suppose I can use some kind of lookup method the get from random index # to character array of alphabet. I'll check stdio. Thanks

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

                If all you need is the ASCII character corresponding to the given integer than a cast is enough, e.g.

                printf("%c\n", (char) RANDOM);

                In testa che avete, signor di Ceprano?

                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