C Language: Pointers 19

Self-defined function using pointers(Selfupr())

Important Question:

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

Example:

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

#include<stdio.h>
void selfupr(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);
  selfupr(n);
  printf("String in upper case is %s\n",n);
  return(0);
}

Output:

Enter any string hello
String in upper case is HELLO