nova verzija tcp+udp->serial com

clubbing.cpp

Committer:
bosko001
Date:
2020-04-05
Revision:
2:45b351b4fc2a
Child:
3:1196befeace0

File content as of revision 2:45b351b4fc2a:

#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;

    }
    
}