Skip to content

Instantly share code, notes, and snippets.

@OxiBo
Last active July 28, 2017 04:40
Show Gist options
  • Save OxiBo/a6c32f7bee4f3c1eb90529478ce89b7b to your computer and use it in GitHub Desktop.
Save OxiBo/a6c32f7bee4f3c1eb90529478ce89b7b to your computer and use it in GitHub Desktop.
CS50 week 2 initials_more
/**
* CS50 week 2 initials_more
*/
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
int main(void)
{
// get input from a user (a full name)
string s = get_string();
if (s!=NULL)
{
//check if first characters are not spaces
int n=-1;
do
{
n++;
}
while (s[n] ==' ');
// print the first character of the given name
printf("%c", toupper (s[n]));
//iterate over the characters in the string one at a time
for (int i=n+1, m = strlen(s); i<m;i++)
{
if (s[i]==' '&&s[i+1]>='A'&&s[i+1]<='z')
{
printf("%c", toupper (s[i+1]));
}
}
printf("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment