Results 1 to 5 of 5

Thread: hi there, newish to C, need a little help *RESOLVED*

  1. #1

    Thread Starter
    Member
    Join Date
    May 2002
    Posts
    37

    hi there, newish to C, need a little help *RESOLVED*

    hi there, im creating a little proggy for uni and have come accross a couple of things i just cant find on the NET. so i thought id ask one of the pros, here it is....

    btw, its a simple C dos window app thingy

    1) me program has a few Yes/No questions and then 'IF' statements are based on the answers, how can i disable the keyboard only letting the user press the 'y' or 'n' key. My friend has it done, but wont tell me how.

    2) is there a way to restart the app? it envolves the user inputting a set of questions (age, y/n Q's, etc) and then displays a summary (is this info correct), what i want to do is, if the user presses the 'n' key (as in, no the info is not correct) to restart the app from the beginning thus going throw the input stage again

    i hope this makes sense, and i would be grateful if one of you guys could help me with this
    Last edited by Bond0r; Jan 21st, 2003 at 01:44 PM.

  2. #2

    Thread Starter
    Member
    Join Date
    May 2002
    Posts
    37
    so is this realy hard and/or not possible?

  3. #3
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Not hard - it's basic programming 101 stuff.

    I do not want to do your homework for you.

    Here's one piece:
    Code:
    #include <ctype.h>
    #include <stdio.h>
    #include <curses.h>
    char y_or_n(void){
            char answer;
            while(1){
                  answer=toupper(getch() );
                  if (answer=='Y' || answer =='N') break;
                 // you can also test for esc which is 27
            }
            return answer;
    }
    Use the y_or_no function like this:
    Code:
         printf("Do you want to quit? Y/N ");
         response=y_or_n();

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    As for the second question:
    Code:
    char correct = 0;
    while(correct != 'Y') {
      // your whole app here
    
      correct = toupper(getch());
    }
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Member
    Join Date
    May 2002
    Posts
    37
    thz guys, just wanna get a little extra into this app (its not required) coz i know ive got a big C assignment comming up and so wanna get a few tricks under meh sleve.

    ta again

Posting Permissions

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



Click Here to Expand Forum to Full Width