0

int main(int argc, string argv[])

{

for (int i = 1; i < argc; i++)

{
    printf("%c", toupper(argv[i][0]));
}
    printf("\n");

}

My code does everything asked of pset2 Initials! I can't seem to figure out how to incorporate the GetString function to prompt the user, mine does it from the command line. Please help! I know that I have to, for example, use string s = GetString(); and then use that variable to print the first character of each word in the string. My code already does this, I am just wrong in that I can't figure out how to incorporate the variable, s, after getting the string. It works fine if I am just taking input from the command line, I don't understand where I am going wrong. I feel like I am missing something or altogether in the wrong frame of mind of how to go about it. Please help, thank you!!!

11
  • This may sound harsh, but this is friendly advice to help you successfully use this forum. When you ask a question, you need to be specific questions and give details about what you have done, what you haven't done, and what results they've produced. When I read your question, I couldn't even figure out what part of pset2 you were working on. This could greatly affect an answer. Next, Vince tried to help you with the exact example of how to use GetString(), which I assume you downvoted. Yet, in your reply to Mark, you said that you were looking for an example. (continued....)
    – Cliff B
    Feb 16 '16 at 0:47
  • In light of the scant info that you provided, Mark was right to point out that no command line parameters were used in this assignment. The lesson here is to ask specific and detailed questions and provide information so that people can make informed responses. Everyone here is trying to help.
    – Cliff B
    Feb 16 '16 at 0:49
  • I appreciate everyone trying to help, but it feels like people, you included, aren't reading everything. I said that my code does exactly what is asked in the pset, which is produce capitalized initials, I also said that mine does it via the command line, which I also said that I know it is not supposed to, because I know it is supposed to use the GetString function. The post is tagged with 'initials' because that is the part of the pset I am working on. I never asked for an example of how GetString works, I got that part. People shouldn't take a down vote so personally.
    – Jared
    Feb 16 '16 at 0:56
  • I don't see where I was vague and what prompted you to lecture me on how to use the forum. You seemed to have taken everything I said negatively for some reason when I was just commenting on what seemed like other people not understanding what I was asking help on.
    – Jared
    Feb 16 '16 at 0:59
  • Jared, I think the issue here is "how do I change my program to use GetString()" is essentially the same as "how do i do initials.c". The only reasonable answer is "use GetString() rather than taking the name from the command line."
    – curiouskiwi
    Feb 16 '16 at 1:01
2

Did you watch any of the videos? They often use GetString(), so you have many examples.

To prompt a user for input:

string s = GetString();

I saw this here: https://youtu.be/vp3TBL4WTbc?t=5s ... but there are many, many other examples if you watch the videos.

Update:

Maybe you meant to ask what to do with the string you get from GetString()?

Iterate over the string you get back from GetString() and identify the characters that come after spaces. Then you can capitalize and print those characters. Try storing each character in another variable as you iterate over the string. Before you set the variable to the current character in the string, check it to see if it contains a space. If it does, that means the last character was a space and the current character needs to be capitalized and printed.

I'm pretty sure that if I show actual code, I'll be breaking the rules.

5
  • Yes, did you read my entire post? My code does exactly what it needs to, but it takes its input from the command line, not from GetString. I know that I need to use GetString and I know how it works, I just don't know how to integrate it into my existing code.
    – Jared
    Feb 16 '16 at 0:32
  • I read your entire post, but the pset requires you to prompt the user for input. Just put that line in your code and use the s variable where you would normally use argv[1]. You also have to iterate over the string using a for loop and you have to identify the characters that come after spaces so that you know which letters to capitalize. i.e. if the last character was a space, capitalize this character and print it.
    – Vince
    Feb 16 '16 at 1:22
  • Thank you Vince! I apologize if my first comment came off as rude. Are you saying that I need more than one for loop? Or just that mine is wrong?
    – Jared
    Feb 16 '16 at 1:26
  • @Jared Nope, only one for loop is needed. There's only one value to iterate over: the string you get back from GetString(). I updated my answer because I think I have a better understanding of what you're asking now. Don't worry about offending me... I have a very thick skin :P You have to develop that to endure programming forums and mailing lists :D
    – Vince
    Feb 16 '16 at 1:40
  • No rule breaking, I wouldn't want you to just give me the code. THANK YOU! I think the problem was that I was coming at it from the wrong angle. I got it to work with a command line argument, so I assumed it would only need a small tweak to incorporate the GetString function, but without it I guess there is a lot more to what I needed to do to make it work. I will keep messing with it until I figure it out or get stuck again.
    – Jared
    Feb 16 '16 at 1:42
0

you wont be using command-line arguments for initials :)

1
  • Yeah I know that, my issue is using GetString to prompt the user. I don't know how to take what I have and make it so it doesn't take a command line argument and instead prompts the user for a name.
    – Jared
    Feb 16 '16 at 0:08

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