Q:

how to use isdigit() in C

So I'm trying to use a isdigit() to check for non numeric values and for some reason when I put in a integer i get a floating exception error and my generated printf statement "invalid input".  I am quite confused on why when i enter a digit it goes into my if statement where it is only true if it is NOT an integer 
#include <stdio.h>
#include <ctype.h>

int main()
{
  int hour=0, minute=0, total=0, maxDiveTime=0, counter=0, average=0;
  printf ("Enter dive times in the format of HH:MM (hours:minutes), Enter \\0 to stop\n");
  while (scanf("%d:%d",&hour, &minute) ! = '\0')
  {
    if ((! isdigit(hour)) || (! isdigit(minute)))
    {
      printf("Invalid Input\n");
      break;
    }
    else
    {
      if (((hour*60)+minute) > (maxDiveTime))
      {
        maxDiveTime = ((hour*60)+minute);
      }
      total = total + (hour*60) + minute;
      counter ++;
    }
  }
    average = total/counter;
    printf("The total divetime is %d:%d\n", total/60, total%60);
    printf("The average divetime is %d:%d\n", average/60, average%60);
    printf("The max divetime is %d\n", maxDiveTime );
    return 0;
}

A:

First, the reason for the floating exception is that count in expression total/count is zero when you break when entering the loop the first time or when you do not enter the loop at all.  So check count before calculating something.  Second, scanf returns the number of values successfully read in, which should be 2 in your case.  Third, isdigit expects a character, i.e. something like '0', not an integer ranging from 0 to something.  When scanf with %d succeeds, you have already successfully read in a number (and nothing else). 
int main()
{
  int hour=0, minute=0, total=0, maxDiveTime=0, counter=0, average=0;
  printf ("Enter dive times in the format of HH:MM (hours:minutes), Enter \\0 to stop\n");
  while (scanf("%d:%d",&hour, &minute) == 2)
  {
      if (((hour*60)+minute) > (maxDiveTime))
      {
        maxDiveTime = ((hour*60)+minute);
      }
      total = total + (hour*60) + minute;
      counter ++;
  }

  if (count > 0) {
    average = total/counter;
    printf("The total divetime is %d:%d\n", total/60, total%60);
    printf("The average divetime is %d:%d\n", average/60, average%60);
    printf("The max divetime is %d\n", maxDiveTime );
  }
    return 0;
}

