0

in this code on enter a number loop runs that many times but I can input data when loop runs for first time **clockformat is just a function that converts 12-hour clock to 24-hour clock

#include<stdio.h>
#include<string.h>
#include<conio.h>
void clockformat(char *a)
void main()
{
    int i,t,n;
    printf("enter the number of test cases ");
    scanf("%d",&t);
    char meettime1[8],availtime[17],meettime[8];
    for(i=1;i<=t;i++)
    {
        char meettime[8];
        printf("enter meeting time\n");
        gets(meettime);
        clockformat(&meettime[0]);
        printf("time in 24 hour format = %s\n",meettime);
        printf("%d\n",i);
        
    }
}

Running program with input:- 3 and 11:23 PM and 04:34 PM

enter the number of test cases 3
enter meeting time
time in 24 hour format =
1
enter meeting time
11:23 PM
time in 24 hour format = 23:23 PM
2
enter meeting time
04:34 PM
time in 24 hour format = 16:34 PM
3

1,2,3 are just to show that loop is running 3 times but I cannot give input for first time.

methead
  • 15
  • 4
  • Also, [Why is the gets function so dangerous that it should not be used?](https://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous-that-it-should-not-be-used). Use `fgets` instead. – kaylum Mar 10 '21 at 22:55
  • Just as a side note: It is unsafe to use `scanf` without checking the return value. See this page for further information: [A beginners' guide away from scanf()](http://sekrit.de/webdocs/c/beginners-guide-away-from-scanf.html) – Andreas Wenzel Mar 10 '21 at 23:09
  • I am new in stackoverflow...I posted this question and it was closed in seconds..with a link to the answer...I want to know who closed it?...and can I ask again if I did not get the answer?? – methead Mar 10 '21 at 23:13

0 Answers0