bosko lekovic
/
ETHtoCOM_10
nova verzija tcp+udp->serial com
Diff: clubbing.cpp
- Revision:
- 2:45b351b4fc2a
- Child:
- 3:1196befeace0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clubbing.cpp Sun Apr 05 12:56:41 2020 +0000 @@ -0,0 +1,49 @@ +#include "clubbing.h" + + + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> + + +int test_num( char *s ) +{ + int m=strlen(s), n=0, i; + for( i=0; i<m; i++) + if( isdigit(s[i]) ) n++; + if(i==n) return 1; + return 0; +} + +int test_ip( char *s ) +{ + char str[16]; + strncpy( str, s, 16); + + + int d = strlen(str); + + if( d < 7) return 0; + else + { + int k=0; + for( int i=0; i<d; i++) + if( str[i] == '.' ) k++; + if(k != 3 ) { return 0; } + k=0; + char *token; + token = strtok(str, "."); + while( token != NULL ) + { + if( test_num(token) ) k++; + token = strtok(NULL, "."); + } + if(k==4) return 1; + else return 0; + + } + +} +