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. negative values for char

negative values for char

Scheduled Pinned Locked Moved C / C++ / MFC
question
15 Posts 6 Posters 2 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.
  • M Offline
    M Offline
    micutzu
    wrote on last edited by
    #1

    Hello, I have the following situation: Input is char *buf (which is the content of a web page). I have the following code char v; for (i=0; i I get a negative v if the page has Greek characters I get negative values for v. Something like v=-50. Is there any method to get the character behind -50 ? Thanks.

    J K N 3 Replies Last reply
    0
    • M micutzu

      Hello, I have the following situation: Input is char *buf (which is the content of a web page). I have the following code char v; for (i=0; i I get a negative v if the page has Greek characters I get negative values for v. Something like v=-50. Is there any method to get the character behind -50 ? Thanks.

      J Offline
      J Offline
      James R Twine
      wrote on last edited by
      #2

      Sounds like you should be scraping the content of the page as Unicode (wide chars, wchar_t) instead of ANSI (narrow chars, char).    The standard ASCII table, which you are really using like-it-or-not when dealing with char types, does not have a lot of extended characters in it, and the ones it has can be treated differently by different systems.  For example, -50 is 0xCE, which can be Î or ╬, or some other character...    Peace!

      -=- James
      Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
      Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
      See DeleteFXPFiles

      M 1 Reply Last reply
      0
      • J James R Twine

        Sounds like you should be scraping the content of the page as Unicode (wide chars, wchar_t) instead of ANSI (narrow chars, char).    The standard ASCII table, which you are really using like-it-or-not when dealing with char types, does not have a lot of extended characters in it, and the ones it has can be treated differently by different systems.  For example, -50 is 0xCE, which can be Î or ╬, or some other character...    Peace!

        -=- James
        Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
        Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
        See DeleteFXPFiles

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

        Thanks for the reply. The whole application is developed around ANSI and changing everyting looks like not such a good idea. I was wandering if there is any mechanism to determine the “real character” behind -50. If I know that the real character is a greek character I can convert it into a html entity for example and I can get something like %u03C.

        N 1 Reply Last reply
        0
        • M micutzu

          Hello, I have the following situation: Input is char *buf (which is the content of a web page). I have the following code char v; for (i=0; i I get a negative v if the page has Greek characters I get negative values for v. Something like v=-50. Is there any method to get the character behind -50 ? Thanks.

          K Offline
          K Offline
          kakan
          wrote on last edited by
          #4

          char is a signed data type. You have to use unsigned char in order to get the character values above 127 (decimal) right, such as:

          unsigned char v;
          for (i=0; i {
          v = (unsigned char) buf[i];
          }

          There is a compiler option (/J ?) that defaults char to be unsigned.

          Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson

          1 Reply Last reply
          0
          • M micutzu

            Hello, I have the following situation: Input is char *buf (which is the content of a web page). I have the following code char v; for (i=0; i I get a negative v if the page has Greek characters I get negative values for v. Something like v=-50. Is there any method to get the character behind -50 ? Thanks.

            N Offline
            N Offline
            Nemanja Trifunovic
            wrote on last edited by
            #5

            If you just want char to be unsigned, set the compiler option /J.


            Programming Blog utf8-cpp

            1 Reply Last reply
            0
            • M micutzu

              Thanks for the reply. The whole application is developed around ANSI and changing everyting looks like not such a good idea. I was wandering if there is any mechanism to determine the “real character” behind -50. If I know that the real character is a greek character I can convert it into a html entity for example and I can get something like %u03C.

              N Offline
              N Offline
              Naveen
              wrote on last edited by
              #6

              I dont know you checked my post or not...but this will work..isnt it? CString cstext = L"03C5"; wchar_t Greek; int nChar; swscanf( cstext, L"%x", &nChar ); Greek = nChar;

              nave

              M T 2 Replies Last reply
              0
              • N Naveen

                I dont know you checked my post or not...but this will work..isnt it? CString cstext = L"03C5"; wchar_t Greek; int nChar; swscanf( cstext, L"%x", &nChar ); Greek = nChar;

                nave

                M Offline
                M Offline
                micutzu
                wrote on last edited by
                #7

                I did . Thanks. I do not use CString (not using MFC). Your solution works but I am trying to find a way to determine if there is a possible to find our which Greek character is assigned to -50 (if there is such a possibility).

                N N 2 Replies Last reply
                0
                • N Naveen

                  I dont know you checked my post or not...but this will work..isnt it? CString cstext = L"03C5"; wchar_t Greek; int nChar; swscanf( cstext, L"%x", &nChar ); Greek = nChar;

                  nave

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

                  Naveen R wrote:

                  CString cstext = L"03C5";

                  naveen, be careful, write this :

                  CStringW cstext = L"03C5";

                  or

                  CString cstext = _T("03C5");

                  but don't mix the two styles. apparently, you're using wide characters in all the rest of your code, so i'd say use the former...


                  [VisualCalc][Flags Beginner's Guide] | [Forums Guidelines][My Best Advice]

                  N 1 Reply Last reply
                  0
                  • M micutzu

                    I did . Thanks. I do not use CString (not using MFC). Your solution works but I am trying to find a way to determine if there is a possible to find our which Greek character is assigned to -50 (if there is such a possibility).

                    N Offline
                    N Offline
                    Naveen
                    wrote on last edited by
                    #9

                    why cant you try printing it out to console..? wprintf( L"%c", pGreek );

                    nave

                    M 1 Reply Last reply
                    0
                    • T toxcct

                      Naveen R wrote:

                      CString cstext = L"03C5";

                      naveen, be careful, write this :

                      CStringW cstext = L"03C5";

                      or

                      CString cstext = _T("03C5");

                      but don't mix the two styles. apparently, you're using wide characters in all the rest of your code, so i'd say use the former...


                      [VisualCalc][Flags Beginner's Guide] | [Forums Guidelines][My Best Advice]

                      N Offline
                      N Offline
                      Naveen
                      wrote on last edited by
                      #10

                      but CString have both constructors CString(LPCWSTR lpsz) CString(LPCSTR lpsz) Any way I did so because he said( in his previous post) his project is UNICODE define...

                      nave

                      T 1 Reply Last reply
                      0
                      • N Naveen

                        but CString have both constructors CString(LPCWSTR lpsz) CString(LPCSTR lpsz) Any way I did so because he said( in his previous post) his project is UNICODE define...

                        nave

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

                        Naveen R wrote:

                        but CString have both constructors

                        this is not acceptable argument, because, if the application is not defining UNICODE macro, even if you initialize your CString with a LPCWSTR, the string will be casted into ANSI string. BTW, i doubt of this information. actually, CString gets a LPCTSTR, which is transformed into LPCSTR or LPCWSTR depending on unicode definition

                        Naveen R wrote:

                        Any way I did so because he said( in his previous post) his project is UNICODE define...

                        yes, but then prefer using CStringW. imagine the case when someone else has to maintain the application, or develop the dual possibility of having the application running both ansi and unicode... your code must be flexible, not only "aware"


                        [VisualCalc][Flags Beginner's Guide] | [Forums Guidelines][My Best Advice]

                        N 1 Reply Last reply
                        0
                        • N Naveen

                          why cant you try printing it out to console..? wprintf( L"%c", pGreek );

                          nave

                          M Offline
                          M Offline
                          micutzu
                          wrote on last edited by
                          #12

                          I did. printf("%c\n", c); wprintf( L"%c", c ); Both print the same character which is not the correct one ┼ (this is printed instead of Π)

                          N 1 Reply Last reply
                          0
                          • M micutzu

                            I did . Thanks. I do not use CString (not using MFC). Your solution works but I am trying to find a way to determine if there is a possible to find our which Greek character is assigned to -50 (if there is such a possibility).

                            N Offline
                            N Offline
                            Nemanja Trifunovic
                            wrote on last edited by
                            #13

                            micutzu wrote:

                            but I am trying to find a way to determine if there is a possible to find our which Greek character is assigned to -50 (if there is such a possibility).

                            That entirely depends on the text encoding. Which charset is the webpage you are working with? If it is Windows CP 1253 (Greek), you can find out by setting the codepage of your console window to 1253 and then printing it out. For -50 (ie 206 in unsigned form) it should be greek capital XI: Ξ


                            Programming Blog utf8-cpp

                            1 Reply Last reply
                            0
                            • T toxcct

                              Naveen R wrote:

                              but CString have both constructors

                              this is not acceptable argument, because, if the application is not defining UNICODE macro, even if you initialize your CString with a LPCWSTR, the string will be casted into ANSI string. BTW, i doubt of this information. actually, CString gets a LPCTSTR, which is transformed into LPCSTR or LPCWSTR depending on unicode definition

                              Naveen R wrote:

                              Any way I did so because he said( in his previous post) his project is UNICODE define...

                              yes, but then prefer using CStringW. imagine the case when someone else has to maintain the application, or develop the dual possibility of having the application running both ansi and unicode... your code must be flexible, not only "aware"


                              [VisualCalc][Flags Beginner's Guide] | [Forums Guidelines][My Best Advice]

                              N Offline
                              N Offline
                              Naveen
                              wrote on last edited by
                              #14

                              toxcct wrote:

                              if the application is not defining UNICODE macro, even if you initialize your CString with a LPCWSTR, the string will be casted into ANSI string.

                              Even if UNICODE is defined, I am expecting only ANSI characters in that statement.

                              toxcct wrote:

                              yes, but then prefer using CStringW

                              Whats is this CStringW? I didnt find any such class in vc6. I havent worked in later verions of visual studio. Is it a new class added to the MFC in later verions of visual studio?

                              nave

                              1 Reply Last reply
                              0
                              • M micutzu

                                I did. printf("%c\n", c); wprintf( L"%c", c ); Both print the same character which is not the correct one ┼ (this is printed instead of Π)

                                N Offline
                                N Offline
                                Naveen
                                wrote on last edited by
                                #15

                                micutzu wrote:

                                wprintf( L"%c", c );

                                if 'c' is of type wchar_t then you must specify like this. wprintf( L"%c", &c );

                                nave

                                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