Expression cannot be evaluated error....very strange!

I am trying to read a file, line by line and parse them to store the information in class variables. It works fine for every variable that I am trying to store except for the name
I am having a strange runtime error (program crashes) when I try to assign the a string of characters into a char pointer variable.

Precisely, I have a sphere class which has among other variables, a char *name.
Here's a sample line from file that I am reading:

1
2
3
4
5
6
7
SPHERE s1 0 0 -10 2 2 1 0.5 0 0 0 1 0 0 50

And..Here's a following snippet of code that parses this line:

num = sscanf(line, "%s %*s %f %f %f %f %f %f %f %f %f %f %f %f %f %d", 
command, newSphere.m_Name, &newSphere.m_Position.x, &newSphere.m_Position.y, &newSphere.m_Position.z,&newSphere.m_ScaleFactor.x, &newSphere.m_ScaleFactor.y, &newSphere.m_ScaleFactor.z,&newSphere.m_Color.red, &newSphere.m_Color.green, &newSphere.m_Color.blue,&newSphere.Ka, &newSphere.Kd, &newSphere.Ks, &newSphere.Kr, &newSphere.n);
 


Here, newSphere.m_Name does not take any value and gives a bad pointer exception!! I found it really strange and have been trying to debug it for ever!! If anyone has a fix for it, please help me out.....its kinda URGENT.

Thanks, I really appreciate it

Not sure if this is your problem

But you need to allocate space in the char* before it is used

eg.
char* newSphere.m_Name = new char[32]

otherwise im not sure what is going on

Hope this was helpful
Shredded
Hi Shredded,

Thanks! It worked :)

I tried allocating memory using malloc before but that didn't work. I also tried declaring char[] array instead of pointer variable and even that didn't work. I didn't try doing this one though :p Thanks again.....it saved me quite a bit of time.

Topic archived. No new replies allowed.