char str[] help
-
Hi I all a newbie here. need help with this: char *strtok( char *str1, const char *str2 ); char str[] = "now # is the time for all # good men to come to the # aid of their country"; char delims[] = "#"; char *result = NULL; result = strtok( str, delims ); while( result != NULL ) { printf( "result is \"%s\"\n", result ); result = strtok( NULL, delims ); } for char str[] , how can i assign it to a variable b? so far i get this error: readin.cpp:34: error: initializer fails to determine size of ‘str Thanks alot.
-
Hi I all a newbie here. need help with this: char *strtok( char *str1, const char *str2 ); char str[] = "now # is the time for all # good men to come to the # aid of their country"; char delims[] = "#"; char *result = NULL; result = strtok( str, delims ); while( result != NULL ) { printf( "result is \"%s\"\n", result ); result = strtok( NULL, delims ); } for char str[] , how can i assign it to a variable b? so far i get this error: readin.cpp:34: error: initializer fails to determine size of ‘str Thanks alot.
xivShin wrote:
char *strtok( char *str1, const char *str2 );
What's the purpose of the above line?
xivShin wrote:
char str[] = "now # is the time for all # good men to come to the # aid of their country"
Is the compiler complaining of the above line? Strange! What compiler are you using? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi I all a newbie here. need help with this: char *strtok( char *str1, const char *str2 ); char str[] = "now # is the time for all # good men to come to the # aid of their country"; char delims[] = "#"; char *result = NULL; result = strtok( str, delims ); while( result != NULL ) { printf( "result is \"%s\"\n", result ); result = strtok( NULL, delims ); } for char str[] , how can i assign it to a variable b? so far i get this error: readin.cpp:34: error: initializer fails to determine size of ‘str Thanks alot.
first address the issue pointed out by the esteemed CPallini then, try either char str[74] = "now # is the time for all # good men to come to the # aid of their country"; or char * str = "now # is the time for all # good men to come to the # aid of their country";
-
Hi I all a newbie here. need help with this: char *strtok( char *str1, const char *str2 ); char str[] = "now # is the time for all # good men to come to the # aid of their country"; char delims[] = "#"; char *result = NULL; result = strtok( str, delims ); while( result != NULL ) { printf( "result is \"%s\"\n", result ); result = strtok( NULL, delims ); } for char str[] , how can i assign it to a variable b? so far i get this error: readin.cpp:34: error: initializer fails to determine size of ‘str Thanks alot.
if b is a pointer: char *b = str; or if b is an array and you need to copy the whole null terminated string to it: #define SIZE 200 // or any suitable value char b[SIZE]; strcpy( b, str ); One suggestion: please use meaningful names as variable names instead of b
-
if b is a pointer: char *b = str; or if b is an array and you need to copy the whole null terminated string to it: #define SIZE 200 // or any suitable value char b[SIZE]; strcpy( b, str ); One suggestion: please use meaningful names as variable names instead of b
Raj Indian wrote:
One suggestion: please use meaningful names as variable names instead of b
b
is soooooooooo meaningful. :rolleyes:If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi I all a newbie here. need help with this: char *strtok( char *str1, const char *str2 ); char str[] = "now # is the time for all # good men to come to the # aid of their country"; char delims[] = "#"; char *result = NULL; result = strtok( str, delims ); while( result != NULL ) { printf( "result is \"%s\"\n", result ); result = strtok( NULL, delims ); } for char str[] , how can i assign it to a variable b? so far i get this error: readin.cpp:34: error: initializer fails to determine size of ‘str Thanks alot.
You don't have a variable b in your program. Therefore it's hard to determine what the message means -- we don't know the type of b. So you need to offer more details.
-
Hi I all a newbie here. need help with this: char *strtok( char *str1, const char *str2 ); char str[] = "now # is the time for all # good men to come to the # aid of their country"; char delims[] = "#"; char *result = NULL; result = strtok( str, delims ); while( result != NULL ) { printf( "result is \"%s\"\n", result ); result = strtok( NULL, delims ); } for char str[] , how can i assign it to a variable b? so far i get this error: readin.cpp:34: error: initializer fails to determine size of ‘str Thanks alot.