Thread: help with simple code (i think!)

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

    help with simple code (i think!)

    hello. can someone give me some advise please.
    i want the user to select an option such as time, date, del etc
    and then the program runs that instruction.
    i can't think of a way to link the two.

    for example:

    below is some code for displaying the time.
    how can i join the command from the user to the instruction to show the time.
    thanks once again.
    i might just complete this work!
    got to be in tomorrow! (ouch!)
    jim






    #include <dos.h>
    #include <stdio.h>


    int main(void)
    {

    char time;


    printf("what do you want to know");
    scanf("%s", time);

    \\DO THIS INSTRUCTION
    \\ELSE DO SOME OTHER INSTRUCTION


    struct dostime_t t;
    _dos_gettime(&t);
    printf("The current time is: %2d:%02d:%02d.%02d\n", t.hour, t.minute,
    t.second, t.hsecond);
    return 0;
    }

  2. #2
    Unregistered
    Guest
    Code:
    #include <stdio.h>
    #include <stdlib.>
    #include <time.h>
    
    int main(void)
    {
      time_t current;
      char sel = '0';
    
      printf("Please choose an option from the following list\n"
             "1. Current Time\n"
             "2. Something else\n"
             "3. Exit\n");
      sel = getchar();
      if(sel == '1')
        printf("%s", ctime(time(&current)));
      else if(sel == '2')
        //do something else
      else if(sel == '3')
        return EXIT_SUCCESS;
      else
        printf("Invalid input!");
    
      return EXIT_SUCCESS;
    }

  3. #3
    Unregistered
    Guest
    Correction:
    somehow the post didn't come out right
    ¤t
    should be
    & current
    without the space in between, this board won't let me post it correctly :P

    weird.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 14
    Last Post: 11-23-2005, 08:53 AM
  2. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Windows Programming
    Replies: 0
    Last Post: 10-14-2002, 01:29 PM
  3. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 12:51 PM
  4. Simple Code, looking for input.
    By Alien_Freak in forum C Programming
    Replies: 3
    Last Post: 03-03-2002, 11:34 AM