0

Written in C I have used this if loop in main function -->

if(islower(ch))

I'm finding the error as

:warning :implicit declaration of function 'islower'
if(islower(ch))

Why is it so?

  • Which language are you using? in C# it should be like :- IsLower(ch). – Nivs Nov 13 '18 at 15:54
  • See [ask]. [Edit] the question and tell us what you want to do, what you have tried, and what results you get, including errors or warnings. Always show your [mcve]. –  Nov 13 '18 at 15:56
  • Probably a duplicate https://stackoverflow.com/q/21213109/1531971 –  Nov 13 '18 at 15:57
  • Please edit the question and mention the programming language. If I can make a guess, I'd say you need to write it as `ch.islower()`. – Dominique Nov 13 '18 at 15:58
  • Possible duplicate of [warning: implicit declaration](https://stackoverflow.com/questions/21213109/warning-implicit-declaration) – Tom Blodget Nov 14 '18 at 07:17

2 Answers2

1

You need to include ctype.h, as follows:

#include <ctype.h>

This header file declares the function islower:

int islower(int c);
user803422
  • 2,636
  • 2
  • 18
  • 36
0

This type of error comes when you call a function before it is defined. Consider the following code:

int main()
{
  char ch= 'a';
  if (islower(ch))
  {
    ch = ch - 32; // difference of ascii values between upper and lower case is 32 
  }

  printf("%c ", ch);
  return 0;
}

int islower(char ch)
{
  if ('a' <= ch && ch <= 'z')
     return 1;
  else
     return 0;
}

You will get that error because you are calling islower() function before defining it. So just give the prototype of the function before calling. You can add int islower(char); line before main as given below.

int islower(char);

int main()
{
  char ch= 'a';
  if (islower(ch))
  {
    ch = ch - 32; // difference of ascii values between upper and lower case is 32 
  }

  printf("%c ", ch);
  return 0;
}

int islower(char ch)
{
  if ('a' <= ch && ch <= 'z')
     return 1;
  else
     return 0;
}

Surely this gonna solve your problem. Hope this helps you. Let me know if anything else is needed.

Akhilesh Pandey
  • 868
  • 8
  • 18
  • Your explanation is correct. But, … your implementation of `islower` gives `warning: comparison of constant ‘122’ with boolean expression is always true` and the algorithm doesn't account for most character encodings and locales like an implementation of the standard library would. (It is unfortunate that syntax and algorithms are taught with text examples because text is very complex.) – Tom Blodget Nov 14 '18 at 07:27
  • Thanks @TomBlodget for finding the bug. Let me know if something is still wrong. – Akhilesh Pandey Nov 14 '18 at 08:00