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. isletter' : not all control paths return a value

isletter' : not all control paths return a value

Scheduled Pinned Locked Moved C / C++ / MFC
question
14 Posts 3 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.
  • M Mark Salsbery

    By the way, you could replace the entire function with a call to _istalpha (isalpha/iswalpha). Mark

    "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

    I Offline
    I Offline
    Immunity18
    wrote on last edited by
    #5

    i had but it create a problem :P

    1 Reply Last reply
    0
    • I Immunity18

      i want to know when a GetAt(i) is not letter (a-z A-Z) so it would be 1234567890!@$#^%^ etc i want this so i can find how many words exist in a string

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #6

      Immunity18 wrote:

      want to know when a GetAt(i) is not letter (a-z A-Z) so it would be 1234567890!@$#^%^ etc

      if (0 == _istalpha(str.GetAt(...)))
      {
      // not a letter
      }

      I don't know what the problem with isalpha/iswalpha was... Regardless, look at your for loop - no matter what the condition, the function returns. To the compiler there's no return after the for loop. If the for loop condition fails before the first iteration, then no value is returned. We know the for loop will always execute (because for (int i = 0 ; i <26 ...) but the compiler doesn't. Mark

      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

      I 1 Reply Last reply
      0
      • M Mark Salsbery

        Immunity18 wrote:

        want to know when a GetAt(i) is not letter (a-z A-Z) so it would be 1234567890!@$#^%^ etc

        if (0 == _istalpha(str.GetAt(...)))
        {
        // not a letter
        }

        I don't know what the problem with isalpha/iswalpha was... Regardless, look at your for loop - no matter what the condition, the function returns. To the compiler there's no return after the for loop. If the for loop condition fails before the first iteration, then no value is returned. We know the for loop will always execute (because for (int i = 0 ; i <26 ...) but the compiler doesn't. Mark

        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

        I Offline
        I Offline
        Immunity18
        wrote on last edited by
        #7

        the _istalpha create me a problem and while it work fine for CStrings intiliaze and valued in code it dont work for CString (buf) from File.txt

        M 1 Reply Last reply
        0
        • I Immunity18

          the _istalpha create me a problem and while it work fine for CStrings intiliaze and valued in code it dont work for CString (buf) from File.txt

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #8

          hmm well I never saw that code so I'm not sure why but it should work on any character you pass to it. There's nothing wrong with using your own function, but you probably want to fix it so it works properly :)

          "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

          I 2 Replies Last reply
          0
          • M Mark Salsbery

            hmm well I never saw that code so I'm not sure why but it should work on any character you pass to it. There's nothing wrong with using your own function, but you probably want to fix it so it works properly :)

            "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

            I Offline
            I Offline
            Immunity18
            wrote on last edited by
            #9

            you can see my code with alpha in below post Different results when , compare 2 strings and 1 str with 1 str from file

            1 Reply Last reply
            0
            • M Mark Salsbery

              hmm well I never saw that code so I'm not sure why but it should work on any character you pass to it. There's nothing wrong with using your own function, but you probably want to fix it so it works properly :)

              "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

              I Offline
              I Offline
              Immunity18
              wrote on last edited by
              #10

              can i ask something the isalpha how it works? i mean i want only A-Z a-z i dont want numbers and !@#$~>time isalpha work for that?

              M 1 Reply Last reply
              0
              • I Immunity18

                can i ask something the isalpha how it works? i mean i want only A-Z a-z i dont want numbers and !@#$~>time isalpha work for that?

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #11

                That's exactly what it does. It returns non-zero if the character is A-Z or a-z. To find something NOT alphabetic then look for it to return 0. From the posts below, it doesn't seem that this is the problem. It looks like you need to step through your code and see exactly what's going on and in what order :) If you are looking for matching words then why are you looking for non-alpha characters. Don't you want to look for whitespace? MArk

                "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                I 1 Reply Last reply
                0
                • M Mark Salsbery

                  That's exactly what it does. It returns non-zero if the character is A-Z or a-z. To find something NOT alphabetic then look for it to return 0. From the posts below, it doesn't seem that this is the problem. It looks like you need to step through your code and see exactly what's going on and in what order :) If you are looking for matching words then why are you looking for non-alpha characters. Don't you want to look for whitespace? MArk

                  "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                  I Offline
                  I Offline
                  Immunity18
                  wrote on last edited by
                  #12

                  whitespaces = " " ? That means this site (Codeproject) wouldn't reveal in my search because it is between ( ) ? i thought an alorithm if the letter in i isn't character + letter in (i-1) is character then we got a word "yes i think works correctly but not in my code :(" so here with that algorith it would find 10 words Well i will alt tab back to Visual studio and alchemy with isalpha To find something NOT alphabetic then look for it to return 0. i think this helped me :D

                  1 Reply Last reply
                  0
                  • I Immunity18

                    i got this warning when i try to use isletter() in my WordDocu() { CString p[26]; CString v[26]; p[0] = "A"; p[1] = "B"; ...... p[24] = "Y"; p[25] = "Z"; v[0] = "a"; v[1] = "b"; .... v[24] = "y"; v[25] = "z"; for (int i = 0 ; i <26 ; i++) { if ( v[i] == str || p[i] == str) { return FALSE; break; } else if ( i==25 &&( v[i] != str && p[i] != str)) { return TRUE; } else { return TRUE; } } } is there any path i dont wrote return TRUE/FALSE ? :/

                    G Offline
                    G Offline
                    GameProfessor
                    wrote on last edited by
                    #13

                    it's so obvious that you forget to return after the loop. You may think that it will definitely return inside the loop (it loops 26 times) but at compile time, the computer can't tell whether the loop will be perform or not. To the compiler, a for() loop is one kind of structure that can be ignored, that's why you have to put a return explicitly after the loop.

                    M 1 Reply Last reply
                    0
                    • G GameProfessor

                      it's so obvious that you forget to return after the loop. You may think that it will definitely return inside the loop (it loops 26 times) but at compile time, the computer can't tell whether the loop will be perform or not. To the compiler, a for() loop is one kind of structure that can be ignored, that's why you have to put a return explicitly after the loop.

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #14

                      GameProfessor wrote:

                      it loops 26 times

                      It loops once ;P

                      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                      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