Hello. For my assignment, my teacher wants me to get 2 numbers from the user, and then valide them. He wants us to use getchar( ). I can get most of it to work using scanf, but using getchar messes everything up. Please help me out.
Code:
#include <stdio.h>
void main(void)
{
char str[256];
int in_val,
status;
char skip_ch;
int error;
printf( "Please enter your name:\t " );
gets(str);
printf("Hello, %s\n", str);
do {
error = 0;
printf("Please enter an integer\t");
in_val = getchar( );
if (in_val != 1) {
error = 1;
scanf("%c", &skip_ch);
printf("Invalid character, %c", skip_ch);
}
do
scanf("%c", &skip_ch);
while (skip_ch != '\n');
}
while (error);
return (in_val);
system("Pause");
}
when using scanf, I did:
Code:
status = scanf("%d", &in_val);
Any ideas?