Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <stdio.h>
#include <cs50.h>
#include <string.h>
int main(void)
{
// take the user's name and capitalize all letters
string name = get_string("enter your name: ");
printf("All Uppercase: ");
// output each character of the user's name
for (int i = 0; i < strlen(name); i++)
{
int is_lower_case = (name[i] >= 'a') && (name[i] <= 'z');
if (is_lower_case)
{
int magic_number = 'a' - 'A'; // always 32 no matter what letter we use
printf("%c", name[i] - magic_number);
}
else
{
printf("%c", name[i]);
}
}
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment