I am working on pset2 initials. and this is the code i have so farenter image description here

the first part of the for loop works properly, because it returns the first letter of the string in uppercase. However, below that code i tired implementing another code that will help me find the first letter of the second name in any given string. What i tired to do was find the location of the white space character and add 1 on to it, so that i can find the first letter of the second name.

Please look at this code and give me feedback ASAP!

  • 1
    In the future, please cut and paste your code into your questions. Inserting an image with the code makes it impossible to copy the code for testing and nobody wants to manually retype it from an image. You might find the following useful: meta.stackexchange.com/questions/22186/…
    – Cliff B
    Jul 31, 2016 at 1:29

1 Answer 1


The code is on the right track, but has a few problems.

THe code prints the first letter, but it does so inside the for loop. That means that it will do so for every pass through the loop.

Except, it may seem that this isn't the case. That's because of the break that follows. That unconditional break will cause the loop to exit immediately, so the remaining code inside the loop will never execute.

Finally, once you get the loop working, if (isspace(s)) will generate a seg fault. The isspace() function takes a single character as input (as you have done with toupper(). ) This is trying to force an entire string down it's throat, so it chokes.

That should take care of most of the problems, no guarantees that there's nothing else lurking, depending on how you rewrite it.

If this answers your questions, 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 .