Change Case

C Programming

C Programming Examples

/* 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