>while isdigit(num) {
while ( isdigit ( num ) )
Here is a more complete example:
Code:
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int valid ( const char *s );
int main ( void )
{
char buff[BUFSIZ];
while ( fgets ( buff, sizeof buff, stdin ) != NULL ) {
char *newline = strrchr ( buff, '\n' );
if ( newline != NULL )
*newline = '\0';
if ( valid ( buff ) )
printf ( "%d\n", atoi ( buff ) );
else
printf ( "Not valid\n" );
}
return 0;
}
int valid ( const char *s )
{
while ( *s != '\0' && isdigit ( *s ) )
s++;
return *s == '\0'; /* Valid if end of string */
}