Skip to content

Instantly share code, notes, and snippets.

@miquilenadiego
Created January 26, 2017 15:30
Show Gist options
  • Save miquilenadiego/cde453d593beb4449d81ba92c48aa6e5 to your computer and use it in GitHub Desktop.
Save miquilenadiego/cde453d593beb4449d81ba92c48aa6e5 to your computer and use it in GitHub Desktop.
initials more comfortable
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
int main (void)
{
string s = get_string();
char f;
int len = strlen(s);
char z[len];
int i;
int k = 0;
if (s[0] != ' ')
{
f = toupper(s[0]);
for (i = 1; i < len; i++)
{
if (s[i] != ' ' && s[i-1] == ' ')
{
z[k] = toupper(s[i]);
k++;
}
}
z[k] = '\0';
printf("%c%s\n", f , z);
}
else
{
for (i = 1; i < len; i++)
{
if (s[i] != ' ' && s[i-1] == ' ')
{
z[k] = toupper(s[i]);
k++;
}
}
z[k] = '\0';
printf("%s\n", z);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment