Hi! I'm learning C.
I want to use strtok_r instead of strtok, but I can't use it although I included "string.h".
How to active this function? I've tried define __STDC_WANT_LIB_EXT1__ 1 but not success.
#define __STDC_WANT_LIB_EXT1__ 1
#include<stdio.h>
#include<string.h>
int main(void) {
char s[]="I'm going to eat a snack hihi";
char *k;
while(!(char *p=strtok_r(s," ",&k)))
puts(s);
getchar();
return 0;
}
/*
Error:
Building test.obj.
C:\Users\Admin\Documents\Pelles C Projects\test\test.c(8): error #2160: Extraneous identifier 'p'.
C:\Users\Admin\Documents\Pelles C Projects\test\test.c(8): error #2001: Syntax error: expected ')' but found '='.
C:\Users\Admin\Documents\Pelles C Projects\test\test.c(8): error #2039: Invalid expression.
C:\Users\Admin\Documents\Pelles C Projects\test\test.c(8): error #2001: Syntax error: expected ')' but found 'strtok_r'.
C:\Users\Admin\Documents\Pelles C Projects\test\test.c(8): warning #2018: Undeclared function 'strtok_r' (did you mean 'strtok_s'?); assuming 'extern' returning 'int'.
C:\Users\Admin\Documents\Pelles C Projects\test\test.c(8): error #2001: Syntax error: expected ';' but found ')'.
C:\Users\Admin\Documents\Pelles C Projects\test\test.c(8): error #2061: Invalid statement termination.
*** Error code: 1 ***
Done.
*/
Another question that when I build above code it give me a ton of errors, I think that I can declare a variable inside a loop at it has allowed since C99, but when I declare a variable inside while loop I get some errors, can someone explain why? Thanks for reading my first post in this box.