Last active
July 28, 2017 04:40
-
-
Save OxiBo/a6c32f7bee4f3c1eb90529478ce89b7b to your computer and use it in GitHub Desktop.
CS50 week 2 initials_more
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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