hey everybody
can anyone helps me, please?
i must program a projekt but i don´t know how i do it.
the projekt:
Write a program to convert from 12-hour time format to 24-hour time format. The 12-
hour format has the form hours:minutes followed by either A, P, AM, or PM (either lower
case or upper case but not mixed). One white space is allowed but not required between
the numerical time and the AM/PM indicator. The 24-hour format must be printed with
leading zeros, to ensure that a 24-hour time always consists of four digits. The output
line is followed by a new-line character.

Recommended Answers

All 2 Replies

What part of the instructions do you not understand? Post what you have attempted to do so far.

I'm guessing that the user provides the time to be converted? If you store the hours and minutes separately in the variables

int hours, mins;

then you can operate on the hours on their own (since that is all you should need to do in order to convert from 12hr to 24hr). The time of day (am/pm) can be stored as a string of length 2

char day[2];

Then let the user input the time to be converted with the scanf statement

scanf("%d:%d %s",&hours,&mins,&day);

You can use the

strcmp()

function to determine the value of the string in

day[]

(make sure you include the string library), and from that you can operate on the value of

hours

accordingly.
Finally, output the converted time with

printf("%d:%d\n",hours,mins);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.