#include <iostream>
#include <cstring>
using namespace std;
char * my_strtok(char *p, const char *str)
{
static char *temp;
int i=0;
static int bit;
if(p!=NULL)
temp = p;
else
temp += bit+1;
while(*(temp+i)!=*str && *(temp+i)!='\0')
{
i++;
}
if(*temp=='\0')
{
temp = NULL;
}
bit = i;
if(temp!=NULL)
*(temp+i) = 0;
return temp;
}
int main()
{
char str[30] = {0};
char ptr[30] = {0};
cout << "input str: " ;
cin >> str;
cout << "input ptr: ";
cin >> ptr;
cout << "str: " << str << endl;
cout << "ptr: " << ptr << endl;
char *p = strtok(str, ".");
cout << "first p: " << p << endl;
while((p=(strtok(NULL, "."))) != NULL)
{
cout << p << endl;
}
char *q = my_strtok(ptr, ".");
cout << "first q: " << q << endl;
while((q=(my_strtok(NULL, "."))) != NULL)
{
cout << q << endl;
}
return 0;
}
IP 点分四段
最新推荐文章于 2024-01-22 21:54:49 发布