include
#include <cs50.h>
#include <string.h>
int main(void)
{
//get user name through stdin
printf("Please enter your name: ");
int lastChar = 32;
string a = get_string();
for(int i = 0; i < strlen(a); i++)
{
if(a[i] != 32 && lastChar == 32) //check if char not space, and last char was a space
{
if(a[i] >= 97 && a[i] <= 122) //checks for lower-case letters, and converts
{
printf("%c", a[i] - 32);
}
else
{
printf("%c", a[i]);
}
lastChar = 0;
}
else if (a[i] == 32) //if char is a space change lastChar to space value
{
lastChar = 32;
}
else //if char is not a space, and last char was not a space, flip lastChar to 0
{
lastChar = 0;
}
}
printf("\n");
return 0;
}
link to check50: https://cs50.me/checks/d327c3669687360ed79d0f0a2fff67f4b960af51