Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- #include <string.h>
- #include <ctype.h>
- int main(int argc, string argv[])
- {
- //ask user for input
- string s = get_string();
- //make sure get_string return a string
- if(s!=NULL)
- {
- //if first letter is a char, print it
- if(s[0] != ' '){
- //check to see if char is lowercase
- if(islower(s[0])){
- //print first letter, to uppercase
- printf("%c", toupper(s[0]));
- } else{
- //print first letter as it is
- printf("%c", s[0]);
- }
- }
- for(int i=0, n=strlen(s); i<n; i++){
- //iterate forward to get the index where char after space is at
- if(s[i-1] == ' ' && s[i] != ' '){
- //check to see if char is lowercase
- if(islower(s[i])){
- //print first letter, to uppercase
- printf("%c", toupper(s[i]));
- } else{
- //print first letter as it is
- printf("%c", s[i]);
- }
- }
- }
- printf("\n");
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement