Menu

Why isalpha() function doesn't work on Dev ?

2002-11-13
2012-09-26
  • Nobody/Anonymous

    Hi,

    Why the isalpha() function doesn't work on Dev-C++ ...

    For example:
    -------------------------------------------------------
    #include <iostream.h>

    void main()
    {
        char a;

        cin >> a;

        if (isalpha(a)){
            cout << "It is a character";
        }
    }
    -----------------------------------------------------------

    This works in Codewarrior ... is there something wrong ? Is there any solution ?

    Thanks ...

    IGonZo

     
    • Anonymous

      Anonymous - 2002-11-13

      When you say "does not work", can you be more specific?  Does it give a compiler error, linker error, or just not print the "Its a character" when you think it should.

      I suggest making sure that the header file ctype.h
      is included in your code, that's where isalpha()
      gets defined.

      minerran

       
    • Nobody/Anonymous

      Well, let me put it this way - it does not work because you coded it wrong.  When the compiler tells you something about implicit definition of a function in the error message, that is its way of saying I have no clue what this function is.  When I see that (and I do, because I bleep up regularly), the first thing I do is see whether I included everything I needed to.

      One other note, it is almost never productive to say "but this works fine on ******!".  This is a special case (You coded it wrong and then blamed the compiler), but also understand that not everything is portable.  Even standard functions can have "special" local enhancements which make them non-portable,  (And you would be suprised how many people ask why function goofbar does not work on Dev, when its a Java or Delphi or Basic function.) 

      Oh, one last thing.  In C++ your main function SHOULD NOT return a void.  Its OK in C, but wrong in C++.  Here is a slightly modified form of your code that compiled and ran fine on Dev 4.9.6.0 - old version on this machine.  Note the use of the pause function to keep the window open.

      Wayne

      include <iostream.h>
      #include <ctype.h>
      #include <stdlib.h>

      int main()
      {
      char a;

      cin >> a;

      if (isalpha(a))
      {
          cout << "It is a character\n";
      }
      else
      {
          cout << "It is not a character\n";
      }
      system("pause");
      return 0;
      }

       
    • Nobody/Anonymous

      By the way, Randy was right on and far more concise than I in finding your problem.

      Thanks sir!

      Wayne

       
    • Nobody/Anonymous

      Wayne,

      Thanks for the compliment although I though your explanation was more detailed then
      mine.  By the way, do you know anything about setting up Dev-C++ to build wxwindows
      programs using mingw32?  I posted a question which unfortunately somehow got duplicated
      and nobody has responded.  If you have any ideas, I'd sure like to hear them.

      Randy

       
    • Nobody/Anonymous

      I have only played with wxwindows a minimal amount. (Which means I am more ignorant than normal, now THERES a SCARY thought)  I have seen, and maybe installed the wxWindows package for Dev, but I have used it zero times.  Sorry to be more uselfess than normal.

      Wayne

      p.s. I may have seemed to have gone off on IGonZo a bit, but I am trying to push the thought on folks that when something goes wrong, the first question you ought to ask is what you might have done wrong, not why won't this tool work right.  This is a lesson most of us took a while to learn, and I am trying to bypass the years of frustration and convey the message short-hand.  Probably failing miserably

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.