Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to convert hh:mm:ss to minutes in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>

double hhmmsstominutes(const char *hhmmss) {
    int hours, minutes, seconds;
    
    // Parse the HH:MM:SS string
    sscanf(hhmmss, "%d:%d:%d", &hours, &minutes, &seconds);

    // Convert to total minutes
    return (hours * 60) + minutes + (seconds / 60.0);
}

int main() {
    printf("%.2f\n", hhmmsstominutes("2:30:00"));
    printf("%.2f\n", hhmmsstominutes("2:35:30"));
    printf("%.2f\n", hhmmsstominutes("5:00:45"));

    return 0;
}

   
   
/*
run:
   
150.00
155.50
300.75
   
*/

 



answered Apr 17, 2025 by avibootz

Related questions

1 answer 63 views
1 answer 67 views
1 answer 66 views
1 answer 82 views
1 answer 72 views
1 answer 75 views
1 answer 71 views
...