0
  1. When there is timeout the program should move to second question and if time out it should say " your time is over ".

  2. Currently my program runs for the first question but not going to second question.

I have tried many time but it doesn't work.

Int main(){
    int time1
    char q1[20]
    printf("\n")
    printf("Enter the malaysia capital name : ");

    alarm(30);
    scanf("%[^\n]",q1);
    
    if (time != SIGALRM)
    {
        alarm(0);
        printf("The Malaysia capital is : '%s'\n",q1);
        printf("\n");
    }

    int time2
    char q1[20]
    printf("\n")
    printf("Enter the malaysian tallest building : ");

    alarm(30);
    scanf("%s",q2);

    if (time2 != SIGALRM)
    { 
        alarm(0);
        printf("Enter the malaysian tallest building is  : '%s'\n",q2);
        printf("\n");
    }
}

Expected :- After time out should move to second question Actual :- Not moving to second question

klutt
  • 30,332
  • 17
  • 55
  • 95
Siva
  • 1

1 Answers1

1

The alarm() function causes SIGALRM to be raised, but you have to use the signal() function first to register a handler for this signal. Your program never registers a handler so there's nothing to run when the signal is raised.

bta
  • 43,959
  • 6
  • 69
  • 99
  • Can someone help me – Siva Sep 12 '19 at 04:02
  • There are a number of questions on this site that have example code for using `signal()` and `alarm()`. For example, see [either of](https://stackoverflow.com/questions/1784136/simple-signals-c-programming-and-alarm-function) [these questions](https://stackoverflow.com/questions/21542077/c-sigalrm-alarm-to-display-message-every-second). – bta Sep 17 '19 at 21:22