This program is able to compile and run succesfully under C++, but not C. The program gives a AccessViolation error message on the first line using NULL. Is there some type of headfile I'm missing? I thought iostream.h allowed me to use null.
I'm using Borland C++ builder ver 5 and 6.
Code:
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <string.h>
#include <stdlib.h>
#include <iostream.h>
int main()
{
char starting_time[10], ending_time[10];
int starting_hour = 0, ending_hour = 0, starting_minute = 0,
ending_minute = 0, hour, minute;
printf("Enter the starting time: ");
scanf("%c", &starting_time);
printf("Enter the ending time: ");
scanf("%c", &ending_time);
starting_hour = atoi( strtok( starting_time, ":" ) );
starting_minute = atoi( strtok( NULL, ":" ) );
ending_hour = atoi( strtok( ending_time, ":" ) );
ending_minute = atoi( strtok( NULL, ":" ) );
hour = ending_hour - starting_hour;
minute = ending_minute - starting_minute;
if ( hour < 0 )
{
hour = hour + 24;
}
if ( minute < 0 )
{
minute = minute + 60;
hour = hour - 1;
}
printf("Elapsed time is: %d : %d", hour, minute);
getch();
return 0;
}