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.
  • S Suresh H

    Thanks Cedric Moonen for the response. ASCII values A – 65 to Z – 90 & a – 97 to z – 122. But hw to check them in the condition ???

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

    Suresh H wrote:

    SCII values A – 65 to Z – 90 & a – 97 to z – 122.

    IsCharAlpha

    "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
    • S Suresh H

      Hi Prasad, Code as no effect its adding all the words. void getoff(char *fname) { ifstream fin; fin.open(fname,ios::in); int wsize; string stemp; //Loops till the end of the file. 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; for(int j =0; j < wsize; j++) { if (isalpha(stemp[j])) { FMap[stemp] = offset; } } } fin.close(); }

      C Offline
      C Offline
      cp9876
      wrote on last edited by
      #19

      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 1 Reply Last reply
      0
      • S Suresh H

        using namespace std; typedef map FileMap; #define SIZE 255 char word[SIZE]; int offset; FileMap FMap; i forgot to enable Ignore HTML tags in this message (good for code snippets) -- modified at 4:30 Friday 30th March, 2007

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

        So FMap is a map to hold string and int, and you want to store words which has only alphates. If this is the senario you are not supposed to insert an item in the map for every charecter checking. Ok here are my questions? 1) How you are diffentiating the words 2) Do you want to remove the special and numeric values and store the string? or totally discarding the string? 3) Is the int value in the needed, whts it going to do if you just want to store the alpha words? -- modified at 5:22 Friday 30th March, 2007 Here is the idea to proceed, 1)Read a word from the file 2)check for any special or numeric chars in the word, if you found any break the loop and goto step 4. 3)If all the chars are alpha then insert in the map 4)continue the above steps untill the end All remaing is only the logical part, think and proceed. -- modified at 5:25 Friday 30th March, 2007


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

        1 Reply Last reply
        0
        • P Parthi_Appu

          You can use, isalpha() API or You can check the chars are alphabet or not.

          if (((stemp[j] >= 65) && (stemp[j] <= 90) ||
          ((stemp[j] >= 97) && (stemp[j] <= 122)))
          /* Alphabet (A-Z) or (a-z) */
          else
          /* Special or Numeric */


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

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

          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 P 2 Replies 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
            Parthi_Appu
            wrote on last edited by
            #22

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


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

            S T 2 Replies 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

              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