C language Check whether string characters are numbers

ww‮ruttual.w‬i.com
C language Check whether string characters are numbers
/*
Example: Check if string is a numberic string in C language
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int isNumber(char s[])
{
    for (int i = 0; s[i]!= '\0'; i++)
    {
        if (isdigit(s[i]) == 0)
              return 0;
    }
    return 1;
}

int main()
{
    char str[] = {"123456"};

    if (isNumber(str) == 0)
        printf("It's not a number\n");
    else
        printf("It's a number\n" );
    return 0;
}
Created Time:2017-08-28 11:22:26  Author:lautturi