Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 15-10-2009
Member
 
Join Date: Apr 2009
Posts: 51
How to convert Seconds to hours in C

Hello friends,

I have tried to make an application which converts seconds into hours, when i am trying to compile it's workign properly but when i try to execute, it's performing wrong result. Can anyone help me out with this issue ?

Code:
#include <stdio.h>
void Second_Hms(int * pSecond);
int main()
{
int sec = 2400;
int hours=0;
int minutes=0;
int second=0;
Second_Hms(&sec);
printf("%d hours %d minutes  %d second", hour, minutes, second);
return 0;
}
void Second_Hms(int * pSecond)
{
int * pMinutes=NULL;
int * pHour=NULL;
*pSecond = *pSecond % 60;
*pMinutes = (*pSecond\/60)%60;
*pHour = *pSecond/3600;
}
Reply With Quote
  #2  
Old 15-10-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Convert Seconds to hours in C

As i see here, you use pointers that point to memory address "NULL" as its name implies, represents nothing. In other words, when you are going to run your program, the operating system will stop immediately because of attempts to access an invalid memory address. So why use pointers to integers, and not just integers?
Reply With Quote
  #3  
Old 15-10-2009
Member
 
Join Date: Apr 2009
Posts: 51
How to convert Seconds to hours in C

As you have said i have changed a little, but it is much better and yet I feel you have entered the course on pointers, and the address, * for the value that it points.

Code:
#include <stdio.h>
void Second_Hms(int * second);
int main()
{
int hour=0;
int minutes=0;
int second=2400;
Second_Hms(&second);
return 0;
}
void Second_Hms(int * second)
{
int * hour;
int * minutes;
*second = *second%60;
*minutes = (*second/60)%60;
*hour = *second/3600;
printf("%d hour %d minutes %d second", hour, minutes, second);
}
Reply With Quote
  #4  
Old 15-10-2009
Member
 
Join Date: Oct 2008
Posts: 167
How to convert Seconds to hours in C

If you don't need any a pointer in your function they you can use the following code.

Code:
void Second_Hms(int second)
{
int hour, minutes;
second = second%60;
minutes = (second/60)%60;
hour = second/3600;
printf("%d hour %d minutes %d second", hour, minutes, second);
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to convert Seconds to hours in C"
Thread Thread Starter Forum Replies Last Post
Computer Freezes for a few seconds about every 20 seconds marcusjb Motherboard Processor & RAM 4 11-12-2011 11:15 PM
PC Shuts Down After A Few Seconds Juggy Hardware Peripherals 8 29-08-2011 06:50 PM
Convert seconds to HH:MM:SS Waffle Windows Software 3 02-09-2009 08:07 PM
C#.NET redirect after 5 seconds Elsie Software Development 2 05-06-2009 11:08 PM
Convert video to iPod, Convert iTunes video, Convert DivX to MP4 tommyhills MediaCenter 1 26-07-2008 02:30 AM


All times are GMT +5.5. The time now is 08:37 PM.