include
include
using namespace std;
char * strtok(char c[],char token){
static char * ptr;
if(c!=NULL){
ptr=c;
}
int i;
char * out=new char(strlen(ptr)+1);
for(i=0;((ptr+i)!=token)&&((ptr+i)!=’\0’);i++){
(out+i)=(ptr+i);
}
*(out+i)=’\0’;
return out;
}
int main(){
char c[]=“hello, i am vipin”;
cout<<strtok(c," “)<<endl;
cout<<strtok(NULL,” “)<<endl;
cout<<strtok(NULL,” “)<<endl;
cout<<strtok(NULL,” ");
return 0;
}
i write this program for strtok function and it is working fine, but i don’t know why.
even i am not incrementing my static pointer ptr.