c Programming getchar putchar: 1 word on each line help plz!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: c Programming getchar putchar: 1 word on each line help plz!

  1. #1
    Join Date
    Sep 2009
    Posts
    1

    Exclamation c Programming getchar putchar: 1 word on each line help plz!

    Heres my code that isnt working... I need it to repeat inputted text word by word, 1 word per line, no punctuation. Thank you! First post btw! i look forward to learning a lot here and spreading the knowledge!

    Code:
    #include <stdio.h>
    #include <ctype.h>
    
    int main(void)
    
    {
        int usertext;
        int newline = 0;
        while ((usertext = getchar() ) !=EOF)
        {
            if (isalpha(usertext) )
            if (ispunct(usertext) )
            if (isspace(usertext) )
                putchar(usertext);
    else
            {
                putchar (usertext);
            }
        }
        return 0;
    }

  2. #2
    Join Date
    Apr 2009
    Posts
    598

    Re: c Programming getchar putchar: 1 word on each line help plz!

    my code that isnt working
    Can you give us more details about the problem, please?

    Anyway, I see one problem which is that your code is not well indented. If it were, then you would see at once that your if() are making an impossible cascade, since a character cannot be a letter of the alphabet, and at the same time be a punctuation and a space:
    Code:
    if (isalpha(usertext) )
       if (ispunct(usertext) )
          if (isspace(usertext) )
             putchar(usertext);
          else {
             putchar (usertext);
          }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center