Jun 27, 2011 at 3:28pm Jun 27, 2011 at 3:28pm UTC
#include"stdio.h"
#include"string.h"
#include"math.h"
void main()
{
char tokens[11][3],text[]="sin(5)+cos(5)",*ptext,*ptokens=tokens[9];int i=0,j,z;
ptext=text;
for(i=0;i<11;i++)
{
for(j=0;j<3;j++)
tokens[i][j]='0';
}
if(*ptext=='s')
{
tokens[i][3]=='sin';
i++;ptext++;
}
if(*ptext=='('||*ptext==')')
{
tokens[i][3]=*ptext;
i++;ptext++;
}
if(*ptext=='c')
{
tokens[i][3]='cos';
i++;ptext++;
}
if(*ptext=='+'||*ptext=='-'||*ptext=='*'||*ptext=='/')
{
tokens[i][3]=*ptext;
i++;ptext++;
}
if(*ptext=='l')
{
tokens[i][3]='log';
i++;ptext++;
}
for(int i=0;i<11;i++)
{
tokens[i][strlen(tokens[i]+1)]='\0';
}
if(*ptext<='9'&&*ptext>='0')
{
tokens[i][3]=*ptext;
i++;ptext++;
}
do
{
printf("%s\r\n",ptokens);
ptokens++;
}
while((*ptokens));
}
this is my code for string parsing but it prints strange characters .so what is wrong in this code .and some times an error appears(stack around variable 'tokens' was corrupted).what can i do ?please any help
Last edited on Jun 27, 2011 at 3:37pm Jun 27, 2011 at 3:37pm UTC
Jun 27, 2011 at 4:47pm Jun 27, 2011 at 4:47pm UTC
Do you have to do it in C, or can you switch to C++?
Jun 27, 2011 at 10:36pm Jun 27, 2011 at 10:36pm UTC
any helllllllllllllp please
Jun 27, 2011 at 10:43pm Jun 27, 2011 at 10:43pm UTC
tokens[i][3]=='sin' ;
Was that meant to be
tokens[i][3]='sin' ;
Jun 27, 2011 at 10:47pm Jun 27, 2011 at 10:47pm UTC
Shouldn't those be in double-quotes anyway?