0

This is my code for initialize....what did I do wrong and what can i do to fix it.

#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, string argv[])
{ 

  printf("Hello, what is your name?");
  string s = GetString();

if(s != NULL)
    {
    for(int i = 0, n = strlen(s); i < n; i++)
    {
        if(islower(s[i]))
        {
            toupper(s[i]);
        }
        if((i == 0) || isspace(s[i - 1]))
        {
            printf("%c", s[i]);
        }
    }
    printf("\n");
    }
}
3

First of all make sure you understand the goal of the program. It's supposed to get a string, for example hello my name is caesar and print it like Hello My Name Is Caesar. So in your for loop you don't have to check if a character is lowercase. In your second if, there is not a pre-declared function named isspace, so unless you specified it yourself (hint: you don't have to), you should just check for s[i - 1] == ' ', and if true, then print this character as uppercase. You are quite close to the solution. Keep trying!

0

All you need is to change this line
toupper(s[i])
to
s[i] = toupper(s[i])

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .