Thread: capitalize every other word. HELP!!!

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    1

    capitalize every other word. HELP!!!

    capitalize every other word. HELP!!!-screen-shot-2013-03-16-5-28-39-pm-jpg

    what am i doing wrong?
    im trying to capitalize every other word. for examples input: hello output: HeLlO

  2. #2
    Registered User
    Join Date
    Jan 2013
    Posts
    55
    Well, my first question to ask you is why did you not include the whole program? It looks like you use some kind of "GetString" function, but I have no idea what you do in that function( Yes I know it probably gets the string, but with what? ). Also, I doubt cs50 is a ANSI C standard preprocessor directive. The corrrect way to use it would be this :

    Code:
    #include "cs50.h"
    Also, why are you using - 23? I'm guessing your trying to decrement the ASCII value perhaps, but if so, you are doing it in a not efficient way. I would suggest using toupper and tolower with a flag that controls when they change the case. That way, it would be easier to control the program the way you want it to be.


    Another question, in your example output, you were capitalizing every letter not the word? Is that your desired result? The title is misleading if so.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Also, I doubt cs50 is a ANSI C standard preprocessor directive. The corrrect way to use it would be this :
    The only difference between the <> and "" when dealing with the include directive is the order in which directories are searched. If you have a "non-standard" header in your include search path then the <> are quite acceptable. And some high profile "standards" require the use of the <> for all occasions, for example the JSF standard.

    Jim

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    In addition to the information provided by BatchProgrammer:

    Code:
    s[i] - 23;
    This does not change anything. You're calculating a value ... and doing nothing with it. If you wish to store it, you must assign the result somewhere.

    Also, in the future, please post your code in code tags, and not as an attached image.

  5. #5
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    ;_;

    Why do we have a picture of text?

    What kind of logic drives this decision?

    I wonder how many gigabytes of video tutorials exist on "Youtube" that are nothing but text dumps?

    *shrug*

    Anyway, I hate to ask, is this bad C or bad C++?

    I know you posted in C, but the `string' thing implies C++.

    [Edit]
    I realize this isn't relevant to the problem at hand, but it significantly changes the help you might receive.
    [/Edit]

    Soma

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by phantomotap View Post
    ;_;

    Anyway, I hate to ask, is this bad C or bad C++?

    I know you posted in C, but the `string' thing implies C++.

    Soma
    The cs50.h is a C header from some school that typedef string as a "char *".

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-27-2013, 06:00 AM
  2. Capitalize first Character in word.
    By duongducthieniu in forum C Programming
    Replies: 10
    Last Post: 01-06-2013, 01:16 AM
  3. Replies: 28
    Last Post: 10-23-2011, 07:17 PM
  4. Capitalize first letter of a word (function)
    By xwielder in forum C++ Programming
    Replies: 13
    Last Post: 10-05-2011, 11:11 PM
  5. Capitalize first letter of every word in .txt file
    By crazygopedder in forum C Programming
    Replies: 9
    Last Post: 10-15-2008, 12:09 PM