Skip to content

Instantly share code, notes, and snippets.

@sojohnnysaid
Created February 11, 2018 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sojohnnysaid/5fd7e9e1a97f0d7b81036a2334f8ed37 to your computer and use it in GitHub Desktop.
Save sojohnnysaid/5fd7e9e1a97f0d7b81036a2334f8ed37 to your computer and use it in GitHub Desktop.
#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