Skip to content

Instantly share code, notes, and snippets.

@sameekapdi
Created October 2, 2017 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sameekapdi/ab2bb0c7b01fb8be3ec25651e1b9d3a7 to your computer and use it in GitHub Desktop.
Save sameekapdi/ab2bb0c7b01fb8be3ec25651e1b9d3a7 to your computer and use it in GitHub Desktop.
#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
string name = get_string();
// Check to ses if string is valid
if (name != NULL)
{
// Find first character and capitalize
int index = 0;
while (name[index] == ' ')
{
index++;
}
printf("%c", toupper(name[index]));
// Iterate through the rest of the string looking for spaces and printing next Letter
for (int i = index + 1, n = strlen(name); i<n; i++)
{
if (name[i] == ' ' && name[i+1] != ' ' && name[i+1] != '\0')
{
printf("%c", toupper(name[i+1]));
}
}
printf("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment