U
Ulrich Vollenbruch
Hi all!
since I'am used to work with matlab for a long time and now have to work
with c/c++, I have again some problems with the usage of strings, pointers
and arrays. So please excuse my basic question:
I want to parse a string like "3.12" to get two integers 3 and 12. I wanted
to use the function STRTOK()
I wrote a main- and a subfunction like:
main() {
int wl=0, il=0;
char *StrIn;
StrIn = "3.12";
printf("%s \n",StrIn);
str2prec(StrIn, wl, il);
}
/******************************************/
void str2prec(char *str_p, int wl, int iwl){
char str_test1[] ="3.12"; //just for testing
char *str_test2 ="3.12"; //just for testing
char *str_split;
printf ("Splitting string \"%s\" in tokens:\n",str_p);
str_split = strtok (str_p,".");
while (pch != NULL)
{
printf ("%s\n",str_split);
str_split = strtok (NULL, " ,.");
}
}
When I use str_p or str_test2 together with STRTOK() this will cause a
memory-error. With str_test1 it works?! Can someone tell why and how I can
manage this problem.
Anyway I would also be happy to hear of some other solutions for string
parsing...
Thanx for any help!
uli
since I'am used to work with matlab for a long time and now have to work
with c/c++, I have again some problems with the usage of strings, pointers
and arrays. So please excuse my basic question:
I want to parse a string like "3.12" to get two integers 3 and 12. I wanted
to use the function STRTOK()
I wrote a main- and a subfunction like:
main() {
int wl=0, il=0;
char *StrIn;
StrIn = "3.12";
printf("%s \n",StrIn);
str2prec(StrIn, wl, il);
}
/******************************************/
void str2prec(char *str_p, int wl, int iwl){
char str_test1[] ="3.12"; //just for testing
char *str_test2 ="3.12"; //just for testing
char *str_split;
printf ("Splitting string \"%s\" in tokens:\n",str_p);
str_split = strtok (str_p,".");
while (pch != NULL)
{
printf ("%s\n",str_split);
str_split = strtok (NULL, " ,.");
}
}
When I use str_p or str_test2 together with STRTOK() this will cause a
memory-error. With str_test1 it works?! Can someone tell why and how I can
manage this problem.
Anyway I would also be happy to hear of some other solutions for string
parsing...
Thanx for any help!
uli