bosko lekovic
/
EthToCom_11
nova proba
clubbing.cpp
- Committer:
- bosko001
- Date:
- 2020-04-08
- Revision:
- 3:1196befeace0
- Parent:
- 2:45b351b4fc2a
- Child:
- 5:c9a908749d4c
File content as of revision 3:1196befeace0:
#include "clubbing.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> /********************** PRINT-ovi *********************************/ void P_niz( char *s, char *niz, int val ) { printf("%s",s); for( int i=0; i < val; i++) printf("%c", niz[i]); printf("\n\r"); fflush(stdout); } void P_int(char *s, int i ) { printf("%s = %d\n\r", s, i); fflush(stdout); } void P_str(const char *s, const char *p ) { printf("%s = %s\n\r", s, p); fflush(stdout); } /************************ IP testovi ****************************/ 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; } }