Mon Jul 02 2018

Change Case

C Programming973 views

File Name: Change-Case-in-C-Programming.c

/* Without strupr() and strlwr()  */
#include<stdio.h>

/* Function use to change string to upper case without strupr() */
void upper_case(char *text) {
	while(*text) {
		if(*text >= 'a' && *text <= 'z')
			*text = *text - 32;
		text++;
	}
}

/* Function use to change string to lower case without strlwr() */
void lower_case(char *text) {
	while(*text) {
		if(*text >= 'A' && *text <= 'Z')
			*text = *text + 32;
		text++;
	}
}

int main() {
	char string[] = "Welcome to Change Case Program";
	upper_case(string);
	printf("String in Upper Case:\n%s\n", string);
	lower_case(string);
	printf("String in Lower Case:\n%s\n", string);
	return 0;
}


/* Output */
String in Upper Case:
WELCOME TO CHANGE CASE PROGRAM

String in Lower Case:
welcome to change case program

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.