Thread: Beginner C programming Please Help!

  1. #16
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    while((ch = getchar()) != EOF)
    ch should be declared as int - otherwise you could not distinguish EOF from the character with the code 0xFF
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  2. #17
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Isn't it already int?

    Oh, whoops. My bad.

    Yeah, getchar() returns an integer, and as vart points out, EOF is (usually) declared as -1. Therefore, if you typed in a 0xFF char (very unlikely unless you're piping input ), it would read as EOF.

    Not what you want.

    Therefore, declare ch and last_ch as integers.
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

  3. #18
    Registered User
    Join Date
    Mar 2009
    hmmm. that's big help!
    thank you so much!
    i just saw that...
    i am not really familiar with those character things, i think i will read the book more and spend a few more hours on this.
    i'm thinking of making a IS_HAWAIIAN function and test it there, if its hawaiian then return true, if not return false
    when it's true it says it's valid
    when its false it says it's invalid
    but then i won't be able to print the word again...

    it's like a mess. oh..

  4. #19
    Registered User
    Join Date
    Mar 2009
    this is my new idea:

    in main:
    while (num != EOF)
    if !is_hawaiian, print invalid
    else, print valid

    in is_hawaiian:
    while white space, ch = getchar
    while it is consonant or vowel
    if ch and last ch is consonant, false;
    if end of word, last isn't vowel, false;

    if (ch == EOF) return EOF
    if not consonant and not vowel return false;

    hope it works.!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 11:48 AM
  2. What are some good beginner programs I shouold make?
    By oobootsy1 in forum C# Programming
    Replies: 6
    Last Post: 08-09-2005, 02:02 PM
  3. Books, Beginner, MustHave
    By Zeusbwr in forum C++ Programming
    Replies: 9
    Last Post: 10-25-2004, 05:14 PM
  4. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM