I tried to make a function that can split a string. (I need to create function that do the same like strtok().)
I wrote something, but it only split the string one time and cant go forward to the next word in the string.
#include <stdio.h>
char * mystrtok(char *s, char delim)
{
static char *p=NULL;
if(s!=NULL) p=s;
if(p==NULL) return NULL;
char *tmp;
tmp=p;
while(1){
if(*p=='\0'){
break;
}
if(*p==delim){
*p='\0';
p++;
break;
}
p++;
}
return tmp;
}
int main()
{
char s[] = "Let us split this string";
// insert your code here:
mystrtok(&s[0], ' ');
printf("%s", s);
mystrtok(NULL, ' ');
printf("%s", s);
mystrtok(NULL, ' ');
printf("%s", s);
return 0;
}
(Im trying to learn the basics so maybe I missed something stupid -_-) TY all!!