I'm new to C and started making a program. Here's how it looks like:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
char input[10000];
printf(" >>> ");
gets(input);
printf("\n\n");
if (strlen(input) > 10000) {
printf(" Input too long (INPUT LENGTH = %d)\n", strlen(input));
return 0;
} else {
char processed_input[10000];
strcpy(processed_input, strsep(input, '$')); //The error is thrown here every time.
if (processed_input[0] == *"calculate") {
printf("helo");
return 0;
}
}
return 0;
}
It isn't completed yet, but my progress stopped when I tried to test run it and it threw this error:
warning: implicit declaration of function 'strsep' [-Wimplicit-function-declaration]
strcpy(processed_input, strsep(input, '$'));
^~~~~~
warning: passing argument 2 of 'strcpy' makes pointer from integer without a cast [-Wint-conversion]
note: expected 'const char *' but argument is of type 'int'
_CRTIMP __cdecl __MINGW_NOTHROW char *strcpy (char *, const char *);
^~~~~~
Can someone please tell me how to fix it?
I tried ChatGPT, other questions of people in Stack Overflow and other platforms, but I still can't find out how to fix it.
strsep()is not a standard C function, it is available on most unix systems, including linux and macOS, but it might not be present on Windows or other legacy systems.Like other unix functions, it might just have been renamed for historical reasons on Windows, so you can try adding this after the
#includelines:If this does not work, use my public domain implementation posted below.
For clarity, here is an abstract of the BSD manual page for
strsep:Note also that your program has other problems:
gets()strsep()takes the address of achar *as its first argument and a string of separators as the second.Here is a modified version: