0

this is my first time on the forum, I am trying initials.c on pset2, I have managed to do the code which gets the first letter of the word and capitalizes it. My problem is when the user enters just a first name or a first and second. I have tried multiple methods all with little success including a do while secondn[0] = \0 and a isblank(). Can you guys possibly point me in the right direction?

int main(void)
{
char firstn[15], secondn[15], thirdn[15];
//Declaring: firstname, middle name and last name, each of can have a maximum of 14 characters accounting for the null zero
 scanf("%s %s %s" , firstn , secondn, thirdn); //Reads the values entered and implements them into the respective character strings

 if (secondn[0] == '\0') // Hopefully sees if secondn has a \0 in it, if it does only print firstn
 {
       printf("%c\n" , toupper(firstn[0]));
 }
 if (thirdn[0] == '\0') // Hopefully sees if thirdn has a \0 in it, if it does only print firstn and secondn
 {
       printf("%c%c\n" , toupper(firstn[0]) , toupper(secondn[0]));
 }

 //do 
 //{
   //    printf("secondname is empty");

 //  }while (secondn[0] == '\0');


 //if (char isblank(char secondn));
 //{
    //   printf("second n is empty");
 //}

    printf("%c%c%c\n" , toupper(firstn[0]) , toupper(secondn[0]) , toupper(thirdn[0])); //Takes character zero of each entity, character zero is the first character as this is zero indexed.

}

1 Answer 1

1

Maybe you should consider a different approach. THe code posted above will only handle 3 names at most. What if there are more?

Perhaps you should consider taking in an entire string and processing it for however many names exist in the string?

You should go back and review the class material related to the assignment, the shorts and especially the content of the pset specification web page and the code provided in the distro.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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