Menu

Is 'tolower()' ANSI C ?

2003-02-14
2012-09-26
  • Nobody/Anonymous

    Is ctype.h an ANSI C header?
    I need to use 'tolower()'.

    If it is not, which ANSI C function i could use instead of tolower?

    Thank you!

     
    • Curtis Sutter

      Curtis Sutter - 2003-02-14

      tolower() and toupper() are located in the iostream header with Dev 4.9.7.4 / gcc 3.2.

      Curtis

       
      • Nobody/Anonymous

        Thanks you, i decided to use ctype.h

        Anyway i think it wont be necessary, i guess what i am trying to do is impossible:

        char TempOcs[13];
        if(strcmp((tolower(TempOcs)), "unnamed.ocs")==0) {
        ...
        }

        I guess tolower/toupper expect a single character not a string right?

         
      • Nobody/Anonymous

        iostream with C? Isnt this only possible with C++?

         
    • Curtis Sutter

      Curtis Sutter - 2003-02-14

      opps, you are right.  I use c++  :-P

      Curtis

       
    • Anonymous

      Anonymous - 2003-02-14

      tolower() and toupper() are ANSI C. The header is ctype.h. They convert single characters only. Converting the case of a string is simple enough:

      char* str_to_lower( char* string )
      {
          char* ptr = string ;
          while( *ptr != 0 )
          {
              tolower( *ptr ) ;
              ptr++ ;
          }

          return( string ) ;
      }

      Returning string allows the function to be used as a parameter, like so:

      if(strcmp((str_to_lower((TempOcs)), "unnamed.ocs")==0)
      {
      // etc.
      }

       

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.