making sure input are digits

hello, everyone. I was wondering if anyone could help me out and tell me how to set up the isdigit() (or another way) to ake sure that the input are all digits and not chars. Also, the way my program is set now you need to rerun it in order to renter the data. Is there any way that i can get it to ask the user to enter data by the program prompting?

thanks

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main(int argc, char * argv[])
{
    int num;
    int rightd;
    int sum = 0;

    printf ("Please enter a positive integer value:");
    scanf("%i", &num);

    if (num <= 1)
    {
         printf ("Invalid integer type, please reenter\n");
         return EXIT_FAILURE;
    }
    else
    {
         while (num != 0)
         {
               rightd = num % 10;
               sum += rightd;
               num /= 10;
          }
     }
      printf ("the sum of the digits is %i\n", sum);
      return EXIT_SUCCESS;
}

Plain ordinary scanf() isn't guaranteed to scan an entire line. %i will scan up to the point where the input stops being digits, in this case, the newline, after which standard input needs to be flushed to get rid of it.

Instead, I reccomend using fgets to input an entire line. That way there's never anything to flush.

But since you're processing the entire string byte by byte, why use scanf at all? Just check it byte by byte:

#include <stdio.h>
#include <ctype.h>

// Returns negative on error, zero or positive on success
int sum_of_digits()
{
  int sum=0;
  int n;
  char buf[512];

  // Prompt
  printf("Enter digits:  ");
  // Read in entire line into buf
  if(fgets(buf,512,stdin) == NULL)
  {
    // If couldn't read, return error
    fprintf(stderr,"Couldn't read from stdin\n);
    return(-1);
  }

  // Loop through entire string
  for(n=0; buf[n]; n++)
  {
    // If it's a newline or carriage return, stop scanning
    if((buf[n] == '\n') || (buf[n] == '\r'))
      break;

    // If it's not a digit, return error
    if(! isdigit(buf[n]))
    {
      fprintf(stderr,"Input string is not digits\n");
      return(-1);
    }

    // Add value of digit to sum
    sum += (buf[n]-'0');
  }

  // Return sum
  return(sum);
}

int main()
{
  while(1)
  {
    int val=sum_of_digits();
    if(val < 0)
      break;

    printf("Sum of digits is %d\n",val);
  }

  return(0);
}