hey everyone i am working on a tic tac toe game were i randomly generate a board when the user inputs a non negative number. so first i have to validate that the user actaully inputed a number and not a letter or a negative number. so far i cant get the program to recognize if the input is negative. but it will recognize if the input is a letter though.
here is my code
Code:
#include <stdio.h>
#include <time.h>
#include <stdbool.h>
#include <ctype.h>
void input(int* num1);
int main(void)
{
int num1;
input(&num1);
return 0;
}
void input(int* num1)
{
bool success = false;
int scanres;
printf("\nPlease enter a non-negative number seed: ");
scanres = scanf("%d", &num1);
if(scanres < 0)
printf("\nYou entered a negative number.");
else if (scanres == 1)
success = true;
else if (scanres == 0)
printf("\nNon-int data.");
else
printf("\nEnd of data stream.");
return ;
}
even though i have the if(scanres < 0)
for some reason it wont recogive that its negative and any negative number passes as true.
please help...the project is due wensday