bosko lekovic
/
EthToCom_11
nova proba
clubbing.cpp@3:1196befeace0, 2020-04-08 (annotated)
- Committer:
- bosko001
- Date:
- Wed Apr 08 08:41:16 2020 +0000
- Revision:
- 3:1196befeace0
- Parent:
- 2:45b351b4fc2a
- Child:
- 5:c9a908749d4c
ver 04 od 8.4.20
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bosko001 | 2:45b351b4fc2a | 1 | #include "clubbing.h" |
bosko001 | 2:45b351b4fc2a | 2 | |
bosko001 | 2:45b351b4fc2a | 3 | |
bosko001 | 2:45b351b4fc2a | 4 | |
bosko001 | 2:45b351b4fc2a | 5 | #include <stdio.h> |
bosko001 | 2:45b351b4fc2a | 6 | #include <stdlib.h> |
bosko001 | 2:45b351b4fc2a | 7 | #include <string.h> |
bosko001 | 2:45b351b4fc2a | 8 | #include <ctype.h> |
bosko001 | 2:45b351b4fc2a | 9 | |
bosko001 | 2:45b351b4fc2a | 10 | |
bosko001 | 3:1196befeace0 | 11 | |
bosko001 | 3:1196befeace0 | 12 | /********************** PRINT-ovi *********************************/ |
bosko001 | 3:1196befeace0 | 13 | |
bosko001 | 3:1196befeace0 | 14 | void P_niz( char *s, char *niz, int val ) |
bosko001 | 3:1196befeace0 | 15 | { |
bosko001 | 3:1196befeace0 | 16 | printf("%s",s); |
bosko001 | 3:1196befeace0 | 17 | for( int i=0; i < val; i++) printf("%c", niz[i]); |
bosko001 | 3:1196befeace0 | 18 | printf("\n\r"); |
bosko001 | 3:1196befeace0 | 19 | fflush(stdout); |
bosko001 | 3:1196befeace0 | 20 | } |
bosko001 | 3:1196befeace0 | 21 | |
bosko001 | 3:1196befeace0 | 22 | void P_int(char *s, int i ) |
bosko001 | 3:1196befeace0 | 23 | { |
bosko001 | 3:1196befeace0 | 24 | printf("%s = %d\n\r", s, i); fflush(stdout); |
bosko001 | 3:1196befeace0 | 25 | } |
bosko001 | 3:1196befeace0 | 26 | |
bosko001 | 3:1196befeace0 | 27 | void P_str(const char *s, const char *p ) |
bosko001 | 3:1196befeace0 | 28 | { |
bosko001 | 3:1196befeace0 | 29 | printf("%s = %s\n\r", s, p); fflush(stdout); |
bosko001 | 3:1196befeace0 | 30 | } |
bosko001 | 3:1196befeace0 | 31 | |
bosko001 | 3:1196befeace0 | 32 | |
bosko001 | 3:1196befeace0 | 33 | |
bosko001 | 3:1196befeace0 | 34 | /************************ IP testovi ****************************/ |
bosko001 | 2:45b351b4fc2a | 35 | int test_num( char *s ) |
bosko001 | 2:45b351b4fc2a | 36 | { |
bosko001 | 2:45b351b4fc2a | 37 | int m=strlen(s), n=0, i; |
bosko001 | 2:45b351b4fc2a | 38 | for( i=0; i<m; i++) |
bosko001 | 2:45b351b4fc2a | 39 | if( isdigit(s[i]) ) n++; |
bosko001 | 2:45b351b4fc2a | 40 | if(i==n) return 1; |
bosko001 | 2:45b351b4fc2a | 41 | return 0; |
bosko001 | 2:45b351b4fc2a | 42 | } |
bosko001 | 2:45b351b4fc2a | 43 | |
bosko001 | 2:45b351b4fc2a | 44 | int test_ip( char *s ) |
bosko001 | 2:45b351b4fc2a | 45 | { |
bosko001 | 2:45b351b4fc2a | 46 | char str[16]; |
bosko001 | 2:45b351b4fc2a | 47 | strncpy( str, s, 16); |
bosko001 | 2:45b351b4fc2a | 48 | |
bosko001 | 2:45b351b4fc2a | 49 | |
bosko001 | 2:45b351b4fc2a | 50 | int d = strlen(str); |
bosko001 | 2:45b351b4fc2a | 51 | |
bosko001 | 2:45b351b4fc2a | 52 | if( d < 7) return 0; |
bosko001 | 2:45b351b4fc2a | 53 | else |
bosko001 | 2:45b351b4fc2a | 54 | { |
bosko001 | 2:45b351b4fc2a | 55 | int k=0; |
bosko001 | 2:45b351b4fc2a | 56 | for( int i=0; i<d; i++) |
bosko001 | 2:45b351b4fc2a | 57 | if( str[i] == '.' ) k++; |
bosko001 | 2:45b351b4fc2a | 58 | if(k != 3 ) { return 0; } |
bosko001 | 2:45b351b4fc2a | 59 | k=0; |
bosko001 | 2:45b351b4fc2a | 60 | char *token; |
bosko001 | 2:45b351b4fc2a | 61 | token = strtok(str, "."); |
bosko001 | 2:45b351b4fc2a | 62 | while( token != NULL ) |
bosko001 | 2:45b351b4fc2a | 63 | { |
bosko001 | 2:45b351b4fc2a | 64 | if( test_num(token) ) k++; |
bosko001 | 2:45b351b4fc2a | 65 | token = strtok(NULL, "."); |
bosko001 | 2:45b351b4fc2a | 66 | } |
bosko001 | 2:45b351b4fc2a | 67 | if(k==4) return 1; |
bosko001 | 2:45b351b4fc2a | 68 | else return 0; |
bosko001 | 2:45b351b4fc2a | 69 | |
bosko001 | 2:45b351b4fc2a | 70 | } |
bosko001 | 2:45b351b4fc2a | 71 | |
bosko001 | 2:45b351b4fc2a | 72 | } |
bosko001 | 2:45b351b4fc2a | 73 | |
bosko001 | 3:1196befeace0 | 74 | |
bosko001 | 3:1196befeace0 | 75 |