Thread: Add on

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    10

    Add on

    Ok,
    I put this question on WindShield's thread, but wasn't sure if it would get read there, so I am going to ask it here. It is a really stupid one. I tried to run the program put forth by WindShield yesterday, with a few minor adjustments. I ran into one basic problem: it didn't stop on the letter 'q'. Why is that? I tried moving it around to different spots, but it didn't change the out put.
    thanks
    Dazed and Confuzed

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    10
    Sorry,
    here's the code that fixed and messed with:
    [code]
    #include <stdio.h>
    #include <ctype.h>

    void makeCap()
    {
    char inChar;
    printf("Please type a sentence: \n");
    while( (inChar = getChar()) =! 'q')
    {
    if (islower(inChar))
    putChar(toupper(inChar));
    }
    }
    int main()
    {
    makeCap()
    return 0;
    }
    [\code]

    thanks
    Dazed and Confuzed

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Read the other thread.

    [edit]OK, we'll keep using this one as you've posted the code here...

    Change your code tags. Check my signature for an example.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>getChar
    >>outChar
    As already stated in the other thread, these two functions need lower case names.

    >>while( (inChar = getChar()) =! 'q')
    The test for not equals is !=

    >>makeCap()
    >>return 0;
    You have a missing semi-colon.

    Try reading and understanding the output from your compiler next time. Debugging is fun and easy once you get the hang of it.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    10
    ok i was looking at the things you said. those were typing errors on my part. when i ran it on my computer, it doesn't give me any problems, except that it doesn't stop on 'q'.
    [code]
    /*#include <stdio.h>
    #include <ctype.h>

    void makeCap()
    {
    char inChar;
    printf("Please type a sentence: \n");
    while( (inChar = getchar()) != 'q')
    {
    if (islower(inChar))
    putchar(toupper(inChar));
    }
    }
    int main()
    {
    makeCap();
    return 0;
    }*/
    [\code]
    Dazed and Confuzed

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Yes, it does, but you need to press the enter key to force the buffered data into your program... and before you ask, there's no standard way of getting unbuffered input from the keyboard.

    As a side note, you are only printing the character out if it was input in lowercase, which makes the output seem a little strange:
    Code:
    Please type a sentence:
    This Is A Sentence
    HISSENTENCE
    And read the link in my signature about code tags. You're using the wrong slash in the ending code tag.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    10
    Ok when I compile this in linux it gives me the spaces and still leaves the already capitalized letters there. But, how do I make it stop when it sees the letter 'q'? I thought that it would do that since i told it to, but I must have had a little miscommunication.
    thanks
    ps. the only conclusion that I can come to is that my program is a guy!

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Ok when I compile this in linux it gives me the spaces and still leaves the already capitalized letters there.
    I don't see how it can. Are you copy/pasting your code to this message board, 'cos what you provided earlier works like I posted above

    >>But, how do I make it stop when it sees the letter 'q'? I thought that it would do that since i told it to, but I must have had a little miscommunication.
    I already answered that one What exactly are you expecting from it? Or is it a case of the code you provided here isn't actually what you compiled/ran?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Registered User
    Join Date
    Nov 2002
    Posts
    10
    It is exactly what I have in my coding. What compiler are you using? When I compile it, it works, except fot the fact that it just doesn't stop on 'q' like i want it to. I have tried moving the != 'q' to other places, and making the 'q' 'Q', but all of these things don't seem to change any of it.
    I am getting:
    "Please enter a sentence:
    /* i entered this: */
    After 4 words, please quit reading.
    /* it gives me: */
    AFTER 4 WORDS, PLEASE QUIT READING."

    It should give me:
    "AFTER 4 WORDS, PLEASE Q"

    Does it make sense what I want it to do?
    thanks again
    Dazed and Confuzed

  10. #10
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Well, first up, here's your code as posted above. I've simply changed the layout to maye it easier to read. I've included the input and output at the end.
    Code:
    #include <stdio.h>
    #include <ctype.h>
    
    void makeCap(void)
    {
        char    inChar;
        printf("Please type a sentence: \n");
        while ((inChar = getchar()) != 'q')
        {
            if (islower(inChar)) putchar(toupper(inChar));
        }
    }
    
    int main(void)
    {
        makeCap();
        return(0);
    }
    /*
     Program output:
    
    Please type a sentence:
    After 4 words, please quit reading
    FTERWORDSPLEASE
    */
    Here's a slightly modified program:
    Code:
    #include <stdio.h>
    #include <ctype.h>
    
    void makeCap(void)
    {
        char    inChar;
        printf("Please type a sentence: \n");
        while ((inChar = getchar()) != 'q')
        {
            inChar = toupper(inChar);
            putchar (inChar);
        }
    }
    
    int main(void)
    {
        makeCap();
        return(0);
    }
    /* 
    output:
    
    Please type a sentence:
    After 4 words, please quit reading
    AFTER 4 WORDS, PLEASE
    */
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  11. #11
    Registered User
    Join Date
    Nov 2002
    Posts
    10

    So aggrivating: )

    Ok,
    I did what you said, but i forgot to add the proto type or does it not need one? When I have the prototype it does what you said and deletes(rather gets rid of) the spaces, number and capitals. Can i just leave it off?
    Thanks
    ps. sorry to bring this up again
    Dazed and Confuzed

  12. #12
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Leave it in. Your functions should be prototyped really.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  13. #13
    Registered User
    Join Date
    Nov 2002
    Posts
    10

    Now to fix the problem

    Ok,
    So, if I leave it in, there is still a problem. How do I get it to read the spaces and the numbers, etc?
    Dazed and Confuzed

  14. #14
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: Now to fix the problem

    Originally posted by ThoughtBubble
    Ok,
    So, if I leave it in, there is still a problem. How do I get it to read the spaces and the numbers, etc?
    There are a couple of versions of the program in my post above. Do they help you?

    If not, can you say what you want your program to do..... maybe give an example of the input and output.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I Can Add!
    By digdug4life in forum C++ Programming
    Replies: 9
    Last Post: 02-07-2005, 03:36 PM
  2. Add a dialog box to a tab
    By axr0284 in forum Windows Programming
    Replies: 0
    Last Post: 01-10-2005, 08:38 AM
  3. can not add member error
    By WaterNut in forum Windows Programming
    Replies: 4
    Last Post: 12-02-2004, 01:18 PM
  4. VC++ Resources - Add Existing Item
    By EliMcGowan in forum Windows Programming
    Replies: 1
    Last Post: 08-30-2004, 02:51 PM
  5. how to add a factorial ()
    By correlcj in forum C++ Programming
    Replies: 14
    Last Post: 10-18-2002, 02:28 PM