I'm using the strtok & strcpy for the program I'm doing. It's sort of a parser of polynomial equations. The strtok function works fine. However, when I try to add the strcpy function to save the tokens in arrays, the program compiles but the exe file sort of crashes and closes.
Here's a sample code of what I'm working on.
Code:
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#define max 50
main()
{
char string[max];
printf("Input string: ");
scanf("%s", &string);
char tokens[max];
char *token = NULL;
int k;
int i=0;
token = strtok(string, " ^+-.x");
while(token != '\0')
{
printf("%s\n", token);
strcpy(&tokens[i++], token);
token = strtok(NULL, " ^+-.x");
}
printf("\n\n");
for(k=0; k<=i; k++)
{
printf("%s\n", &tokens[k]);
}
getch();
return 0;
}