1. ## A simple program?

Hello Everybody.
I'm a beginner programmer in c.
I'm trying to write a program that will ask the user to input a number and if he does not input a number, it tells him that it's not a number.

When i first thought of the idea it looked very easy. But when i tried to do it, I just couldn't find a way.

Help anybody?

2. First read the number as a string, then check every character in the string and see if it's a digit. If you get to the end of the string, it's a number.

Spoilers follow, be warned.
Code:
```#include <stdio.h>
#include <string.h>
#include <ctype.h>

int isnumber( char *number ) {
while ( *number ) {
if ( !isdigit( *number++ ) ) {
return 0;
}
}

return 1;
}

int main( void ) {
char number[256];

fgets( number, sizeof number, stdin );
number[strlen( number ) - 1] = '\0';

if ( isnumber( number ) ) {
printf( "It's a number\n" );
} else {
printf( "Not a number\n" );
}

return 0;
}```

3. If you weren't so lazy, you would have found the FAQ, instead of having someone do it for you. I wish we still had candy.

Quzah.

4. You can also try to read numbers with a self-written function, only using getchar() and some simple logic:

Code:
```int c;
signed int number = 0;
int neg = 0;

while ((c = getchar()) != '\n' && c != ' ')
{
if (c == '-' && number == 0)
neg = !neg;
if (c >= '0' && c <= '9')
if (neg)
number = (number * 10) - (c - '0');
else
number = (number * 10) + (c - '0');
}```
The function isn't very robust if you enter stuff like "-356-25" but it should just illustrate how you could do it.