вот например:
Код:
#include <stdio.h>
#include <conio.h>
#define SIZE 20
void main(void)
{
int x;
char buffer[SIZE], ch;
int i;
printf("Enter x: ");
ch = 0;
i = 0;
while (i<SIZE-2)
{
ch = getch();
if (ch=='-' && i==0)
{
buffer[i] = ch; // '-' on 1st place = NEGATIVE NUMBER
putch(ch);
i++;
}
else if (ch>='0' && ch <='9')
{
buffer[i] = ch; // add to buffer
putch(ch);
i++;
}
else if (ch==10 || ch==13)
{
break; // user press enter
}
else
{
putch(7); // wrong key = BEEP
}
}
buffer[i] = '\0'; // end of string
printf("\n");
sscanf(buffer,"%d",&x);
printf("%d",x);
}
если что непонятно - спрашивай