Hi
I am trying to make my homework about a command line calculator, and i am trying to divide the entered string into small parts and i am trying to use strtok for this.
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct var
{
char name[10];
double value;
};
void main()
{
char in[100], *temp[10],type;
int i,j,k,temp1,temp2,temp3;
k=0;
printf("Enter the expression >>");
gets(in);
temp[0]=strtok(in," ");
for (i=1;temp[i]!=NULL;i++)
{
temp[i]=strtok(NULL," ");
}
for(k=0;k<10;k++)
{
printf("%s",temp[k]);
}
}
But when i try to execute, it gives me the error "Run-Time Check Failure #2 - Stack around the variable 'temp' was corrupted." and writes <null> 7 times instead of divided string parts. How can i fix it? Or is there any other way to do the same thing.
By the way in my homework, user gives expressions with spaces in between, for example NOT "3+5" but "3 + 5".
Thanks for any help