Write the UPPER function that converts all letters in a string to uppercase.


Difficulty level
Video recording
This exercise is mostly suitable for students
#include <stdio.h>
#include <conio.h>

void UPPER(char str[])
{
	int i = 0;
	for (; str[i]; i++)
		if (str[i] >= 'a' && str[i] <= 'z')
			str[i] = str[i] - 'a' + 'A';
}

void main()
{
	char str[100];
	printf("Enter a string: ");
	gets(str);
	UPPER(str);
	puts(str);

	getch();
}

 

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Implementation of a stack to hold elements of 2 different types