I don't think my code is that accurate for the purpose of this problem. The goal is to print and capitalise the first letters of a user's name. I'm having the most trouble finding out how to move around inside of the string once I discover a white space. I realise that the string should be recognised as an array of characters, and once I have the number of them I can iterate over each character and should be able to call up specific characters within that array. I have read online that this problem shouldn't require an array, argument count/ argument vector and I should be able to get by with a for loop.
What would the community suggest that I try? Perhaps using 'isspace' is the greatest issue in my code. I did try this:
if (s[i] == " ")
But that pulled up two errors that I couldn't work around.
Thanks, everyone.
#include <cs50.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
int main(void)
{
printf("Please provide first and last name:\n");
string s = GetString();
if (s != NULL)
{
for (int i = 0, n = strlen(s); i < n; i++)
// set i to 0, n represents the length of string s, and i < n, i++ will assign placeholders
// i up through n.
{
if (isspace(s[i]))
{
printf("%c %c\n", toupper (s[i] + 1), toupper (s[i] - 1));
}
}
}
}