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 check the ASCII value ??

How to check the ASCII value ??

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
33 Posts 9 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 Parthi_Appu

    :) May be influenced by the subject line...


    Do your Duty and Don't expect the Result
    Rate this Post, if I helped You

    S Offline
    S Offline
    Suresh H
    wrote on last edited by
    #23

    Appu still the problem is there not got the solution still..... i changed the code as below now it only checks for the 1st character if that is valid it will add it to map .. if ( ((stemp[0] >= 65) && (stemp[0] <= 90)) || ((stemp[0] >= 97) && (stemp[0] <= 122)) ) FMap[stemp]=offset; but hwy to check if there is any special character or number in between and hw to add them??

    P 1 Reply Last reply
    0
    • T toxcct

      Parthi_Appu wrote:

      if (((stemp[j] >= 65) && (stemp[j] <= 90) || ((stemp[j] >= 97) && (stemp[j] <= 122)))

      why bothering comparing to ascii values, when you can use the characters literal ?

      if (((stemp[j] >= 'a') && (stemp[j] <= 'z') ||
      ((stemp[j] >= 'A') && (stemp[j] <= 'Z')))


      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #24

      toxcct wrote:

      why bothering comparing to ascii values, when you can use the characters literal ?

      And why to make these comparisons, if isaplha[^] is available ?

      Prasad Notifier using ATL | Operator new[],delete[][^]

      T 1 Reply Last reply
      0
      • P prasad_som

        toxcct wrote:

        why bothering comparing to ascii values, when you can use the characters literal ?

        And why to make these comparisons, if isaplha[^] is available ?

        Prasad Notifier using ATL | Operator new[],delete[][^]

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #25

        prasad_som wrote:

        And why to make these comparisons, if isaplha[^] is available ?

        yes, i totally agree, i was just beating a bit the worst code author :rolleyes:


        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

        P 1 Reply Last reply
        0
        • S Suresh H

          Appu still the problem is there not got the solution still..... i changed the code as below now it only checks for the 1st character if that is valid it will add it to map .. if ( ((stemp[0] >= 65) && (stemp[0] <= 90)) || ((stemp[0] >= 97) && (stemp[0] <= 122)) ) FMap[stemp]=offset; but hwy to check if there is any special character or number in between and hw to add them??

          P Offline
          P Offline
          Parthi_Appu
          wrote on last edited by
          #26

          somehow you retrieve the word and put it in stemp then,

          while(..)
          {
          bool bValid = true;
          for (j = 0; j < wsize; j++)
          {
          if (!(((stemp[0] >= 65) && (stemp[0] <= 90)) ||
          ((stemp[0] >= 97) && (stemp[0] <= 122))))
          {
          bValid = false;
          break;
          }
          }
          if (bValid)
          FMap[stemp] = offset;
          }


          Do your Duty and Don't expect the Result
          Rate this Post, if I helped You

          S 1 Reply Last reply
          0
          • T toxcct

            prasad_som wrote:

            And why to make these comparisons, if isaplha[^] is available ?

            yes, i totally agree, i was just beating a bit the worst code author :rolleyes:


            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

            P Offline
            P Offline
            prasad_som
            wrote on last edited by
            #27

            :). I guess, OP's query is still unsolved. I totally lost him.

            Prasad Notifier using ATL | Operator new[],delete[][^]

            S 1 Reply Last reply
            0
            • P Parthi_Appu

              somehow you retrieve the word and put it in stemp then,

              while(..)
              {
              bool bValid = true;
              for (j = 0; j < wsize; j++)
              {
              if (!(((stemp[0] >= 65) && (stemp[0] <= 90)) ||
              ((stemp[0] >= 97) && (stemp[0] <= 122))))
              {
              bValid = false;
              break;
              }
              }
              if (bValid)
              FMap[stemp] = offset;
              }


              Do your Duty and Don't expect the Result
              Rate this Post, if I helped You

              S Offline
              S Offline
              Suresh H
              wrote on last edited by
              #28

              Hi Appu,, Thank you very much, code is working i made the changes as below while(!fin.eof()) { fin >> word; //strlwr(word); wsize = strlen(word); offset=fin.tellg(); offset = offset - wsize + 1; //Insert Words and its offset in to Map stemp = word; bool bValid = true; for (int j = 0; j < wsize; j++) { if (!isalpha(stemp[j])) { bValid = false; break; } } if (bValid) FMap[stemp] = offset; }

              1 Reply Last reply
              0
              • P prasad_som

                :). I guess, OP's query is still unsolved. I totally lost him.

                Prasad Notifier using ATL | Operator new[],delete[][^]

                S Offline
                S Offline
                Suresh H
                wrote on last edited by
                #29

                Hi Prasad, Thank you very much for the help. i made changes a below and its working now perfectly. i had never used isalpha so i was with ascii code, thanks for the info. while(!fin.eof()) { fin >> word; //strlwr(word); wsize = strlen(word); offset=fin.tellg(); offset = offset - wsize + 1; //Insert Words and its offset in to Map stemp = word; bool bValid = true; for (int j = 0; j < wsize; j++) { if (!isalpha(stemp[j])) { bValid = false; break; } } if (bValid) FMap[stemp] = offset; }

                1 Reply Last reply
                0
                • S Suresh H

                  Hello All, I am trying a read text file and extracting words from it and adding to a map. I want to add only valid words and eliminate numbers and special character words and then add it to map. Invalid words like 1word , hello# , t2o etc … so I want to eliminate all the number and special characters. Can anyone please help me with this …. strlwr(word); wsize = strlen(word); stemp = word; for(int j =0; j<=wsize; j++) { if ( stemp[j] == '.' || stemp[j] == ';' || stemp[j] == '*' || stemp[j] == '#' && stemp[j] == '!' || stemp[j] == '@' || stemp[j] == '$' || stemp[j] == '%' && stemp[j] == '^' || stemp[j] == '&' || stemp[j] == '(' || stemp[j] == ')' && stemp[j] == '-' || stemp[j] == '+' || stemp[j] == '/' ) break; else FMap[stemp]=offset; } This conditions are very lengthy, is there any way I can reduce it by checking the ASCII value and add them to MAP. Thanking you, Suresh HC.

                  D Offline
                  D Offline
                  Don Box
                  wrote on last edited by
                  #30

                  Use _isascii

                  Come online at:- jubinc@skype

                  P 1 Reply Last reply
                  0
                  • D Don Box

                    Use _isascii

                    Come online at:- jubinc@skype

                    P Offline
                    P Offline
                    prasad_som
                    wrote on last edited by
                    #31

                    Don Box wrote:

                    _isascii

                    OP wanted to know if given character is in range a-z or A-Z. I wonder, why you have suggested this function ?

                    Prasad Notifier using ATL | Operator new[],delete[][^]

                    1 Reply Last reply
                    0
                    • C cp9876

                      Look carefully at

                      for(int j =0; j < wsize; j++)
                      {
                      if (isalpha(stemp[j]))
                      {
                      FMap[stemp] = offset;
                      }
                      }

                      Do you really want to add an entry to FMap every time you find an alpha character, or everytime you find a word with ALL the characters alpha?

                      Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

                      T Offline
                      T Offline
                      ThatsAlok
                      wrote on last edited by
                      #32

                      cp9876 wrote:

                      if (isalpha(stemp[j]))

                      humm!

                      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                      cheers, Alok Gupta Global Interface Table: An Easy Way to Marshal an Interface Pointer[new] VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                      1 Reply Last reply
                      0
                      • P Parthi_Appu

                        :) May be influenced by the subject line...


                        Do your Duty and Don't expect the Result
                        Rate this Post, if I helped You

                        T Offline
                        T Offline
                        ThatsAlok
                        wrote on last edited by
                        #33

                        Parthi_Appu wrote:

                        :) May be influenced by the subject line...

                        might be. many people get influenced by subject line

                        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                        cheers, Alok Gupta Global Interface Table: An Easy Way to Marshal an Interface Pointer[new] VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                        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