自己来结贴了。未做零点的判断:
程序如下:
#include <ctype.h>
int main(void)
{
int b,c;
char ch;
printf("Enter a 12-hour time:");
scanf("%d:%d",&b,&c);
//printf("%d:%d",b,c);
while((ch=getchar())!=' ')
;
while((ch=getchar())!='\n'){
if(tolower(ch)=='p')
b +=12;
//else
//
putchar(ch);
}
//bh=getchar();
printf("Equivalent 24-hour time:%.2d:%.2d",b,c);
printf("\n");
return 0;
}