Click here to Skip to main content
15,887,596 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: To make a function in C which does not except "\n" & EOF as input. Pin
David Crow3-Jan-18 5:02
David Crow3-Jan-18 5:02 
AnswerRe: To make a function in C which does not except "\n" & EOF as input. Pin
Tarun Jha3-Jan-18 5:45
Tarun Jha3-Jan-18 5:45 
QuestionRe: To make a function in C which does not except "\n" & EOF as input. Pin
David Crow3-Jan-18 5:48
David Crow3-Jan-18 5:48 
AnswerRe: To make a function in C which does not except "\n" & EOF as input. Pin
Tarun Jha3-Jan-18 5:54
Tarun Jha3-Jan-18 5:54 
GeneralRe: To make a function in C which does not except "\n" & EOF as input. Pin
David Crow3-Jan-18 6:02
David Crow3-Jan-18 6:02 
GeneralRe: To make a function in C which does not except "\n" & EOF as input. Pin
leon de boer3-Jan-18 14:45
leon de boer3-Jan-18 14:45 
GeneralRe: To make a function in C which does not except "\n" & EOF as input. Pin
Richard MacCutchan3-Jan-18 21:54
mveRichard MacCutchan3-Jan-18 21:54 
QuestionC Program to Calculate Difference Between Two Time Periods . Pin
Tarun Jha31-Dec-17 12:27
Tarun Jha31-Dec-17 12:27 
I am not able to understand the logic used in the program below. Can someone elaborate how does the logic works in this program.

C++
<pre>#include <stdio.h>

struct TIME
{
  int seconds;
  int minutes;
  int hours;
};
void differenceBetweenTimePeriod(struct TIME t1, struct TIME t2, struct TIME *diff);

int main()
{
    struct TIME startTime, stopTime, diff;

    printf("Enter start time: \n");
    printf("Enter hours, minutes and seconds respectively: ");
    scanf("%d %d %d", &startTime.hours, &startTime.minutes, &startTime.seconds);

    printf("Enter stop time: \n");
    printf("Enter hours, minutes and seconds respectively: ");
    scanf("%d %d %d", &stopTime.hours, &stopTime.minutes, &stopTime.seconds);

    // Calculate the difference between the start and stop time period.
    differenceBetweenTimePeriod(startTime, stopTime, &diff);

    printf("\nTIME DIFFERENCE: %d:%d:%d - ", startTime.hours, startTime.minutes, startTime.seconds);
    printf("%d:%d:%d ", stopTime.hours, stopTime.minutes, stopTime.seconds);
    printf("= %d:%d:%d\n", diff.hours, diff.minutes, diff.seconds);

    return 0;
}

//not able to understand the logic.
void differenceBetweenTimePeriod(struct TIME start, struct TIME stop, struct TIME *diff)
{
    //how does this logic works??.
    if(stop.seconds > start.seconds){
        --start.minutes;
        start.seconds += 60;
    }

    diff->seconds = start.seconds - stop.seconds;
    if(stop.minutes > start.minutes){
        --start.hours;
        start.minutes += 60;
    }

    diff->minutes = start.minutes - stop.minutes;
    diff->hours = start.hours - stop.hours;
}



Thank you

modified 31-Dec-17 18:35pm.

AnswerRe: C Program to Calculate Difference Between Two Time Periods . Pin
Richard MacCutchan31-Dec-17 22:42
mveRichard MacCutchan31-Dec-17 22:42 
AnswerRe: C Program to Calculate Difference Between Two Time Periods . Pin
jschell1-Jan-18 6:22
jschell1-Jan-18 6:22 
GeneralRe: C Program to Calculate Difference Between Two Time Periods . Pin
Richard MacCutchan1-Jan-18 7:36
mveRichard MacCutchan1-Jan-18 7:36 
GeneralRe: C Program to Calculate Difference Between Two Time Periods . Pin
jschell3-Jan-18 13:08
jschell3-Jan-18 13:08 
GeneralRe: C Program to Calculate Difference Between Two Time Periods . Pin
Tarun Jha1-Jan-18 13:42
Tarun Jha1-Jan-18 13:42 
Questionnon-user interface event such as a DDE, OLE Pin
_Flaviu31-Dec-17 3:25
_Flaviu31-Dec-17 3:25 
AnswerRe: non-user interface event such as a DDE, OLE Pin
Victor Nijegorodov31-Dec-17 4:09
Victor Nijegorodov31-Dec-17 4:09 
GeneralRe: non-user interface event such as a DDE, OLE Pin
_Flaviu31-Dec-17 9:59
_Flaviu31-Dec-17 9:59 
QuestionHow to Read/Write schema file .xsd in c++ Pin
brraj28-Dec-17 19:15
brraj28-Dec-17 19:15 
AnswerRe: How to Read/Write schema file .xsd in c++ Pin
Richard MacCutchan28-Dec-17 21:24
mveRichard MacCutchan28-Dec-17 21:24 
GeneralRe: How to Read/Write schema file .xsd in c++ Pin
brraj1-Jan-18 17:49
brraj1-Jan-18 17:49 
GeneralRe: How to Read/Write schema file .xsd in c++ Pin
Richard MacCutchan1-Jan-18 22:57
mveRichard MacCutchan1-Jan-18 22:57 
GeneralRe: How to Read/Write schema file .xsd in c++ Pin
brraj1-Jan-18 23:01
brraj1-Jan-18 23:01 
AnswerRe: How to Read/Write schema file .xsd in c++ Pin
jschell1-Jan-18 6:30
jschell1-Jan-18 6:30 
GeneralRe: How to Read/Write schema file .xsd in c++ Pin
brraj1-Jan-18 17:56
brraj1-Jan-18 17:56 
GeneralRe: How to Read/Write schema file .xsd in c++ Pin
jschell3-Jan-18 13:08
jschell3-Jan-18 13:08 
QuestionStruct type and memory Pin
Anonygeeker27-Dec-17 18:17
Anonygeeker27-Dec-17 18:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.