My initials program, although it appears correct, fails check50. I'm not sure why - check50 says its not printing a new line, but it does in the terminal. Please help me identify the problem:
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
int main(void)
{
string s = get_string(); // Prompting user for name
if (s != NULL) // Making sure string is valid
{
int j = 1;
printf("%c", toupper(s[0])); // Printing first character in uppercase
// Second Character (If Possible)
do
{
j++;
}
while (s[j] != ' ' && j < strlen(s)); // Iterate through letters of string, starting with second letter, until reaches ' '
int k;
k = j;
do
{
k++;
}
while (s[k] == ' ' && k < strlen(s)); //Iterate through letters of string, starting with second letter, until reaches char != ' '
printf("%c", toupper(s[k]));
// Third Character (If possible)
int l;
l = j;
do
{
l++;
}
while (s[l] != ' ' && l < strlen(s)); // Iterate through letters of string, starting with second letter, until reaches ' '
int m;
m = l;
do
{
m++;
}
while (s[m] == ' ' && m < strlen(s)); //Iterate through letters of string, starting with second letter, until reaches char != ' '
printf("%c", toupper(s[m]));
}
printf("\n"); //Print a new line
}