C Language: Pointers 20

Self-defined function using pointers(Selflwr())

Important Question:

C program using pointers, write a user-defined function named “selflwr()” to convert the string to upper case? (All upper case alphabets are converted to lower case, rest remain as it is).

 

Example:

1.
n=”HELLO”
Output:
hello
2.
n=”ComPUter12″
Output:
computer12

#include<stdio.h>
void selflwr(char *p)
{
	while(*p!='\0')
	{
		if(*p>='A' && *p<='Z')
		*p=*p+32;

		p++;
	}
}
int main()
{
  char n[20];
  printf("Enter any string ");
  gets(n);
  selflwr(n);
  printf("String in lower case is %s\n",n);
  return(0);
}

Output:

Enter any string HELLO
String in lower case is hello