first commit
This commit is contained in:
48
CS4210/Project 3/common/strtok_r/strtok_r.c
Normal file
48
CS4210/Project 3/common/strtok_r/strtok_r.c
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "include/strtok_r.h"
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
char *strtok_r(char *s, const char *delim, char** s3)
|
||||
{
|
||||
char *pR;
|
||||
short bDone=0;
|
||||
size_t i,j;
|
||||
|
||||
if(s != NULL){
|
||||
*s3 = s;
|
||||
}
|
||||
if(**s3 == '\0'){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for(;;){
|
||||
bDone = 1;
|
||||
for(j=0; *(delim+j) != '\0'; j++){
|
||||
if(**s3 == *(delim+j)){
|
||||
**s3 = '\0';
|
||||
(*s3)+=1;
|
||||
bDone = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(bDone == 1){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0; *(*s3+i) != '\0'; i++){
|
||||
|
||||
for(j=0; *(delim+j) != '\0'; j++){
|
||||
if(*(*s3+i) == *(delim+j)){
|
||||
pR = *s3;
|
||||
*(*s3+i) = '\0';
|
||||
*s3 += i+1;
|
||||
|
||||
return pR;
|
||||
}
|
||||
}
|
||||
}
|
||||
pR = *s3;
|
||||
*s3 += i;
|
||||
return pR;
|
||||
}
|
||||
Reference in New Issue
Block a user