Hello everyone! I'm having somewhat of a problem trying to sort this out. In this program i want for the scanf to only read one digit, and in case the user inputs characters or other numbers following that digit, ideally the program would disregard said characters and numbers. Furthermore, in this program i will have to use two «scanf's», one for the function i want to use, and another for the point in which i want to apply the function.
I appreciate the help.
Here's the program:

Code:
#include <stdio.h>
#include <string.h>
#include <math.h>


void show_help()
{
  printf("\n This program allows you to calculate the derivative of one of the following functions in a certain point.\n\n");
  printf("1: sin(x);\n2: cos(3*x);\n3: tan(x);\n4: asin(x);\n5: acos(x);\n6: log(x);\n7: log10(x);\n8: exp(5*x);\n9: 3 cos(2*x) sin(4*x).\n\n");
}




double derivada ( double (*func) (double), double ponto )
{
  double deriv, f1, h, f2;
  h = 1e-6 * ponto;
  f1 = func(ponto + h);
  f2 = func(ponto);


  deriv = (f1-f2)/h;


  return deriv;
}


double cos3x ( double valor )
{
  return cos(3*valor);
}






double exp5x ( double valor )
{
  return exp(5*valor);
}






double cos_sin ( double valor )
{
  return (3*cos(2*valor)*sin(4*valor));
}


double dcos3x ( double valor )
{
  return (-3*sin(3*valor));
}


double dtan ( double valor )
{
  return (1/(cos(valor)*cos(valor)));
}


double dasin ( double valor )
{
  return (1/sqrt(1-(valor*valor)));
}


double dacos ( double valor )
{
  return (-1/sqrt(1-(valor*valor)));
}


double dlog ( double valor )
{
  return (1/valor);
}
double dlog10 ( double valor )
{
  return (1/(valor*log(10)));
}


double dexp5x ( double valor )
{
  return (5*exp(5*valor));
}


double dcos_sin ( double valor )
{
  return (-6*sin(2*valor)*sin(4*valor)+12*cos(2*valor)*cos(4*valor));
}


int main ()
{


  int c, p, w, d, t1;
  double a, b, z;
  double (*funcao)(double);
  double (*f2)(double);




  show_help();


  while(1)
    {


      printf("Input a number from 1 to 9 corresponding to the function you want to apply the derivative, and the respective point.\n");


      d = scanf("%d", &c);


      if (d == 0)
	{
	  printf("\nError!  You need to input a number!\n");
	  break;
	}


      if (c == 0)
	{
	  show_help();
	  printf("Input a number from 1 to 9 corresponding to the function you want to apply the derivative, and the respective point.\n\n");
	  scanf("%d", &c);
	}


      if ( c > 9 || c < 0 )
	{
	  printf("\nError! The number %d does not correspond to any function.\n", c);
	  continue;
	}


      t1=scanf("%lf", &b);


      if(t1 == 0)
      {
          printf("Erro! You need to input a number corresponding to the point you want to apply the derivative of the fucntion!");
          break;
      }
      if(b == 0)
      {
          printf("Erro! Function is divided by 0.\n");
          continue;
      }


      if(c == 1)
	{
	  funcao = sin;
	  f2=cos;
	}


      if(c == 2)
	{
	  funcao = cos3x;
	  f2=dcos3x;
	}


      if(c == 3)
	{
	  funcao = tan;
	  f2=dtan;
	}


      if(c == 4)
	{
	  if ( b<=-1 || b>=1 )
	    {
	      printf("ERROR! Function isn't defined in that point\n");
	      continue;
	    }
	  funcao = asin;
	  f2=dasin;


	}


      if(c == 5)
	{
	  if ( b<=-1 || b>=1 )
	    {
	      printf("ERROR! Function isn't defined in that point\n");
	      continue;
	    }
	  funcao = acos;
	  f2=dacos;


	}


      if(c == 6)
	{
	  if ( b<=0 )
	    {
	      printf("ERROR! Function isn't defined in that point.\n");
	      continue;
	    }
	  funcao = log;
	  f2=dlog;


	}


      if(c == 7)
	{
	  if ( b<=0 )
	    {
	      printf("ERROR! Function isn't defined in that point.\n");
	      continue;
	    }


	  funcao = log10;
	  f2=dlog10;
	}


      if(c == 8)
	{
	  funcao = exp5x;
	  f2=dexp5x;
	}


      if(c == 9)
	{
	  funcao = cos_sin;
	  f2=dcos_sin;
	}




      a=derivada(funcao,b);
      z=f2(b);
      printf("Derivada=%lf\n",a);
      printf("Derivada exata=%lf.\n",z);
      printf("Erro resultante da aproximação efetuada = %0.8lf.\n",(z-a));


      printf("Pretende continuar?\nSe sim pressione 1, caso contrário digite outro número.\n");
      w= scanf("%d",&p);
      if(p != 1 || w==0)
	break;


    }
  return 0;
}