C Programming

Change Case

Learn C programming for change case of the text without using strupr and strlwr function

7/2/2018
0 views
Change-Case-in-C-Programming.cC
/* 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
C programmingC codingChange Casestruprstrlwr

Related Examples