isnumber function
==============
check before atoi,atof the string you want to convert
Code:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int isNumber(char []);
int isNumber(char text[]){
int isit=1;
for(int i=0;i<strlen(text);i++){
if (!isdigit(text[i])){
isit=0;
break;
}
}
return isit;
}
int main (){
char str1[]="1g776ad";
char str2[]="1776d";
char str3[]="g1776";
char str4[]="1776";
printf("\n<1=true , 0=false> isnumber=%d",isNumber(str1));
printf("\n<1=true , 0=false> isnumber=%d",isNumber(str2));
printf("\n<1=true , 0=false> isnumber=%d",isNumber(str3));
printf("\n<1=true , 0=false> isnumber=%d",isNumber(str4));
getchar();
return 0;
}