Advertisement

l-values???

Started by August 20, 2003 12:21 AM
19 comments, last by adam17 21 years, 6 months ago
WOW i didnt think i would get this many replies this quickly. Most of you are VERY close in guessing how my code is written. Mat_array is a vector of classes. i have written my own class for the material properties, and Mat_file is a character array for storing the location of the file. S_stream is a string not a char array, so it can be compared. Here i will repost my code snippet with some corrections.
string  S_stream;char    stream[sizeof(int)];      //dummy for reading in char    Mat_file[sizeof(int)];    //Mat_file is declared within the MATERIAL classvector Mat_array;       //array of materials...if(S_stream == "*BITMAP"){	fscanf(infile, "%s", &stream);--->    Mat_array[num_mat].Mat_file = stream;} 

The arrow (--->) is where im getting the error. i hope this clears the problem up a bit. Im still a little confused on what is wrong.

Umm... yeah... that would be great... -Bill Lumberg
quote:
Original post by adam17
vector Mat_array; //array of materials
...
---> Mat_array[num_mat].Mat_file = stream;



without the header file, can't check everything, but...
make sure the subscript operator is overloaded (and returns a value) and vectory::Mat_file is public (or only access it from a member function of the class)
also for whatever type vector::Mat_file is (guessing string), make sure the = operator is overloaded for it.

[edited by - tricona on August 20, 2003 2:00:30 PM]
Advertisement
quote:

Most of you are VERY close in guessing how my code is written.


*mutters some not very nice curses* And, why on earth do we have to go guessing in the first place? If you want people to help, you shouldn't make it a complete riddle to them... that aside:

quote:

---> Mat_array[num_mat].Mat_file = stream;



If i got you right Mat_file is a char-array (>"Mat_file is a character array for storing the location of the file").
So is stream ("char stream[sizeof(int)];").
Hence assigning them via '=' is still not legal. (Like Fruny pointed out hours ago)

Use strcpy(...), or switch to std::string and std::iostream entirely.

PS. I still don't get the logic behind using sizof(int) for you array sizes...

[edited by - Wildfire on August 20, 2003 2:17:17 PM]
How do I set my laser printer on stun?
ok ok i give ill post my code just to help you help me out. just be forwarned it can be pretty nasty...
/*struct	LAYER{	string		Name,				Class,				Location,				Filter;	int			Subno,				Noise_level;	float		Amount,				Angle,				Blur,				Blur_offset,				Noise_amt,				Noise_size,				Noise_phase;	POINT		Offset,				Tiling;};*/struct	MATERIAL{	char		Mat_name[sizeof(int)];	char		Mat_file[sizeof(int)];	Vector3		rgb_Ambient;	Vector3		rgb_Diffuse;	Vector3		rgb_Specular;	float		Transparency;};struct	MESH{	int					num_vertex,		//number of vertices						num_faces,		//number of faces						num_t_vertex,	//number of textured vertices						num_t_face,		//number of textured faces						mat_id;			//texture ID	vector<Vector3>		vertex;			//holds xyz values for vertices	vector<Face>		face;			//holds 3 floats for triangle vertices	vector<Vector3>		fnormal;		//holds 3 floats for face normals	vector<Vector3>		vnormal;		//holds 3 floats for vertex normals	vector<Vector3>		tvertex;		//holds 3 floats for textured vertices	vector<Face>		tface;			//holds 3 integers for textured faces (index value)};/////////////////STREAM VARIABLES/////////////////string				S_stream;char				stream[sizeof(int)];////////////////////////////////////////////////////////////////////FILE VARIABLES//////////////////FILE				*infile;ofstream			outfile;///////////////////////////////////////////////////////////////////GLOBAL VARIABLES/////////////////static	GLuint		map = NULL;int					num_obj = 0;int					num_mat = 0;vector<MESH>		Mesh_array;vector<MATERIAL>	Mat_array;//////////////////////////////////////////////////////////////////FUNCTION PROTOTYPES///////////////GLuint				Import(char *fname, GLuint map);void				Import_Obj();void				Import_Mat();GLuint				Draw_Triangles();//////////////////////////////////////////////////GLuint Draw_Triangles(){	outfile << "DRAW_TRIANGLES()" << endl;	double	v1, v2, v3;	float	v_n1, v_n2, v_n3;	//float	f_n1, f_n2, f_n3;	float	tex_x, tex_y;	int		index = 0;	int		normal_ind = 0;	int		tex_ind = 0;	map = glGenLists(1);	glNewList(map, GL_COMPILE);	for(int loop1=0; loop1<num_obj; loop1++)	{				outfile << "Loop1#" << loop1 << endl;		glBindTexture(GL_TEXTURE_2D, texture[loop1]);		glColor4f(1, 1, 1, 1);		for(int loop2=0; loop2<Mesh_array[loop1].num_faces; loop2++)		{			outfile << "Loop2#" << loop2 << endl;			glBegin(GL_TRIANGLE_STRIP);					outfile << "Begin Triangles" << endl;			v1 = v2 = v3 = 0;							outfile << "Init v1, v2, v3" << endl;			index = 0;									outfile << "Init index" << endl;			v_n1 = v_n2 = v_n3 = 0;						outfile << "Init f_n1, f_n2, f_n3" << endl;			tex_x = tex_y = 0;							outfile << "Init tex_x, tex_y" << endl;			index = Mesh_array[loop1].face[loop2].x;	outfile << "ind " << index << endl;			tex_ind = Mesh_array[loop1].tface[loop2].x;			tex_x = Mesh_array[loop1].tvertex[loop2].x;			tex_y = Mesh_array[loop1].tvertex[loop2].y;			v_n1 = Mesh_array[loop1].vnormal[index].x;	outfile << "v_n1 " << v_n1 << endl;			v_n2 = Mesh_array[loop1].vnormal[index].y;	outfile << "v_n2 " << v_n2 << endl;			v_n3 = Mesh_array[loop1].vnormal[index].z;	outfile << "v_n3 " << v_n3 << endl;			v1 = Mesh_array[loop1].vertex[index].x;		outfile << "v1  " << v1 << endl;			v2 = Mesh_array[loop1].vertex[index].y;		outfile << "v2  " << v2 << endl;			v3 = Mesh_array[loop1].vertex[index].z;		outfile << "v3  " << v3 << endl;			glTexCoord2f(tex_x, tex_y);			glNormal3f(v_n1, v_n2, v_n3);				outfile << "	Normal" << endl;			glVertex3f(v1, v2, v3);						outfile << "	Vertex" << endl;			index = Mesh_array[loop1].face[loop2].y;	outfile << "ind " << index << endl;			tex_ind = Mesh_array[loop1].tface[loop2].y;			tex_x = Mesh_array[loop1].tvertex[loop2].x;			tex_y = Mesh_array[loop1].tvertex[loop2].y;			v_n1 = Mesh_array[loop1].vnormal[index].x;	outfile << "v_n1 " << v_n1 << endl;			v_n2 = Mesh_array[loop1].vnormal[index].y;	outfile << "v_n2 " << v_n2 << endl;			v_n3 = Mesh_array[loop1].vnormal[index].z;	outfile << "v_n3 " << v_n3 << endl;			v1 = Mesh_array[loop1].vertex[index].x;		outfile << "v1  " << v1 << endl;			v2 = Mesh_array[loop1].vertex[index].y;		outfile << "v2  " << v2 << endl;			v3 = Mesh_array[loop1].vertex[index].z;		outfile << "v3  " << v3 << endl;			glTexCoord2f(tex_x, tex_y);			glNormal3f(v_n1, v_n2, v_n3);				outfile << "	Normal" << endl;			glVertex3f(v1, v2, v3);						outfile << "	Vertex" << endl;			index = Mesh_array[loop1].face[loop2].z;	outfile << "ind " << index << endl;			tex_ind = Mesh_array[loop1].tface[loop2].z;			tex_x = Mesh_array[loop1].tvertex[loop2].x;			tex_y = Mesh_array[loop1].tvertex[loop2].y;			v_n1 = Mesh_array[loop1].vnormal[index].x;	outfile << "v_n1 " << v_n1 << endl;			v_n2 = Mesh_array[loop1].vnormal[index].y;	outfile << "v_n2 " << v_n2 << endl;			v_n3 = Mesh_array[loop1].vnormal[index].z;	outfile << "v_n3 " << v_n3 << endl;			v1 = Mesh_array[loop1].vertex[index].x;		outfile << "v1  " << v1 << endl;			v2 = Mesh_array[loop1].vertex[index].y;		outfile << "v2  " << v2 << endl;			v3 = Mesh_array[loop1].vertex[index].z;		outfile << "v3  " << v3 << endl;			glTexCoord2f(tex_x, tex_y);			glNormal3f(v_n1, v_n2, v_n3);				outfile << "	Normal" << endl;			glVertex3f(v1, v2, v3);						outfile << "	Vertex" << endl;			glEnd();		}			}	glEndList();	outfile.close();	return map;}void Import_Mat(){	fseek(infile, 0L, SEEK_SET);	while(!feof(infile))	{		fscanf(infile, "%s", &stream);		S_stream = stream;		if(S_stream == "*MATERIAL")		{			num_mat++;			Mat_array.reserve(256);					Mat_array.resize(num_mat);			//outfile << "*MATERIAL" << endl;		}		if(S_stream == "*BITMAP")		{			fscanf(infile, "%s", &stream);			Mat_array[num_mat].Mat_file = stream;		}	}	texture.resize(num_mat);	for(int i=0; i<num_mat; i++)	{		BuildTexture(Mat_array[i].Mat_file, texture[i]);	}}void Import_Obj(){	fseek(infile, 0L, SEEK_SET);														//Sets file pointer to beginning	while(!feof(infile))																//Checks to see if the eof has been reached	{		fscanf(infile, "%s", &stream);													//Scans the next string to compare		S_stream = stream;																//Converts 'string' to char string'		if(S_stream == "*GEOMOBJECT")													//Changes to new storage vector for next object		{			num_obj++;																	//Increases global number of objects			Mesh_array.reserve(256);													//Reserves space for 256 objects			Mesh_array.resize(num_obj);													//Resizes global storage vector to hold next object			//outfile << "*GEOMOBJECT" << endl;												//Logging Output		}				if(S_stream == "*MATERIAL_REF")													//Imports material ID		{			fscanf(infile, "%i", &Mesh_array[num_obj-1].mat_id);						//Converts value to int						//outfile << "*MATERIAL_REF" << endl;											//Logging Output		}		if(S_stream == "*MESH_NUMTVERTEX")												//Imports number of textured vertices		{			fscanf(infile, "%i", &Mesh_array[num_obj-1].num_t_vertex);					//Converts value to int			//outfile << "NUM tVERTEX" << endl;												//Logging Output		}		if(S_stream == "*MESH_NUMTVFACES")												//Imports number of terxtured faces		{			fscanf(infile, "%i", &Mesh_array[num_obj-1].num_t_face);					//Converts value to int			//outfile << "NUM tFACE" << endl;												//Logging Output		}		if(S_stream == "*MESH_TVERTLIST")												//Imports list of textured vertices		{			fscanf(infile, "%s", &stream);												//Imports bracket			for(int i=0; i<Mesh_array[num_obj-1].num_t_vertex; i++)						//Loops for number of textured vertices			{				fscanf(infile, "%s", &stream);											//Imports "*MESH_TVERT"				fscanf(infile, "%s", &stream);											//Imports index value				fscanf(infile, "%f", &Mesh_array[num_obj-1].tvertex[i].x);				//Converts to float				fscanf(infile, "%f", &Mesh_array[num_obj-1].tvertex[i].z);				//Swap Y and Z values for 3D Studio				fscanf(infile, "%f", &Mesh_array[num_obj-1].tvertex[i].y);				//               ""			}		}		if(S_stream == "*MESH_TFACELIST")												//Imports list of textured faces		{			fscanf(infile, "%s", stream);												//Imports brackets			for(int i=0; i<Mesh_array[num_obj-1].num_t_face; i++)						//Loops for number of textured faces			{				fscanf(infile, "%s", &stream);											//Imports "*MESH_TFACE"				fscanf(infile, "%s", &stream);											//Imports index value				fscanf(infile, "%f", &Mesh_array[num_obj-1].tface[i].x);				//Converts to float				fscanf(infile, "%f", &Mesh_array[num_obj-1].tface[i].z);				//Swap Y and Z values for 3D Studio				fscanf(infile, "%f", &Mesh_array[num_obj-1].tface[i].y);				//               ""			}		}		if(S_stream == "*MESH_NUMVERTEX")												//Imports number of vertices		{			fscanf(infile, "%i", &Mesh_array[num_obj-1].num_vertex);					//Converts value to int			Mesh_array[num_obj-1].vertex.resize(Mesh_array[num_obj-1].num_vertex);		//Adjusts size of vertex storage vector			Mesh_array[num_obj-1].vnormal.resize(Mesh_array[num_obj-1].num_vertex);		//Adjusts size of vertex normal storage vector			//outfile << "NUM mVERTEX" << endl;												//Logging Output		}		if(S_stream == "*MESH_NUMFACES")												//Imports number of faces		{			fscanf(infile, "%i", &Mesh_array[num_obj-1].num_faces);						//Converts value to int			Mesh_array[num_obj-1].face.resize(Mesh_array[num_obj-1].num_faces);			//Adjusts size of the face storage vector			Mesh_array[num_obj-1].fnormal.resize(Mesh_array[num_obj-1].num_faces);		//Adjusts size of the face normal storage vector			//outfile << "NUM FACES" << endl;												//Logging Output		}		if(S_stream == "*MESH_VERTEX_LIST")												//Imports list of vertices		{			fscanf(infile, "%s", &stream);												//Inputs bracket			//outfile << "VERTEX LIST:" << endl;											//Logging Output			for(int i=0; i<Mesh_array[num_obj-1].num_vertex; i++)						//Loop through			{				fscanf(infile, "%s", &stream);											//Inputs "*MESH_VERTEX"				fscanf(infile, "%s", &stream);											//Inputs vertex index				//Y and Z values are swapped for 3D Studio files				fscanf(infile, "%f", &Mesh_array[num_obj-1].vertex[i].x);				//Converts x value & stores it				fscanf(infile, "%f", &Mesh_array[num_obj-1].vertex[i].z);				//Converts z value & stores it				fscanf(infile, "%f", &Mesh_array[num_obj-1].vertex[i].y);				//Converts y value & stores it				//outfile << Mesh_array[num_obj-1].vertex.x &lt;&lt; " ";						//Logging Output	<br></font><br>				<font color=gray>//outfile &lt;&lt; Mesh_array[num_obj-1].vertex.y &lt;&lt; " ";						//Logging Output<br></font><br>				<font color=gray>//outfile &lt;&lt; Mesh_array[num_obj-1].vertex.z &lt;&lt; endl;						//Logging Output<br></font><br>			}<br>			<font color=gray>//outfile &lt;&lt; endl;<br></font><br>		}<br>		<br>		if(S_stream == "</font>*MESH_FACE_LIST")												<font color=gray>//Imports vertex indecies<br></font><br>		{<br>			fscanf(infile, <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"%s"</font></font></font></font></font></font>, &stream);												<font color=gray>//Skips a bracket<br></font><br>			<font color=gray>//outfile &lt;&lt; "FACE LIST:" &lt;&lt; endl;												//Logging Output<br></font><br><br>			<font color=blue>for</font>(<font color=blue>int</font> i=0; i&lt;Mesh_array[<font color=purple>num_obj-1</font>].num_faces; i++)						<font color=gray>//Loop through data<br></font><br>			{<br>				fscanf(infile, <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"%s"</font></font></font></font></font></font>, &stream);											<font color=gray>//Skip "*MESH_FACE"<br></font><br>				fscanf(infile, <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"%s"</font></font></font></font></font></font>, &stream);											<font color=gray>//Skip face index<br></font><br><br>				fscanf(infile, <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"%s"</font></font></font></font></font></font>, &stream);											<font color=gray>//Skip 'A'<br></font><br>				fscanf(infile, <font color=darkred><font color=darkred><font color=darkred>"%i"</font></font></font>, &Mesh_array[<font color=purple>num_obj-1</font>].face[<font color=purple>i</font>].x);					<font color=gray>//Converts first index to int<br></font><br><br>				fscanf(infile, <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"%s"</font></font></font></font></font></font>, &stream);											<font color=gray>//Skip 'B'<br></font><br>				fscanf(infile, <font color=darkred><font color=darkred><font color=darkred>"%i"</font></font></font>, &Mesh_array[<font color=purple>num_obj-1</font>].face[<font color=purple>i</font>].y);					<font color=gray>//Converts second index to int<br></font><br><br>				fscanf(infile, <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"%s"</font></font></font></font></font></font>, &stream);											<font color=gray>//Skip 'C'<br></font><br>				fscanf(infile, <font color=darkred><font color=darkred><font color=darkred>"%i"</font></font></font>, &Mesh_array[<font color=purple>num_obj-1</font>].face[<font color=purple>i</font>].z);					<font color=gray>//Converts third index to int<br></font><br><br>				<font color=blue>for</font>(<font color=blue>int</font> loop=0; loop&lt;10; loop++)										<font color=gray>//Skips over windings, smoothing values<br></font><br>					fscanf(infile, <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"%s"</font></font></font></font></font></font>, &stream);<br>			}<br>		}<br><br>		<font color=blue>if</font>(S_stream == "*MESH_NORMALS")													<font color=gray>//Imports triangle normals<br></font><br>		{<br>			fscanf(infile, <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"%s"</font></font></font></font></font></font>, &stream);												<font color=gray>//Skips bracket<br></font><br>			<font color=gray>//outfile &lt;&lt; "MESH NORMALS" &lt;&lt; endl;											//Logging Output<br></font><br><br>			<font color=blue>for</font>(<font color=blue>int</font> i=0; i&lt;Mesh_array[<font color=purple>num_obj-1</font>].num_vertex; i++)						<font color=gray>//Loop through face normals<br></font><br>			{<br>				fscanf(infile, <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"%s"</font></font></font></font></font></font>, &stream);											<font color=gray>//Skips "*MESH_VERTEX"<br></font><br>				fscanf(infile, <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"%s"</font></font></font></font></font></font>, &stream);											<font color=gray>//Skips vertex index<br></font><br><br>				fscanf(infile, <font color=darkred><font color=darkred><font color=darkred>"%f"</font></font></font>, &Mesh_array[<font color=purple>num_obj-1</font>].fnormal[<font color=purple>i</font>].x);				<font color=gray>//Converts x vertex value to int<br></font><br>				fscanf(infile, <font color=darkred><font color=darkred><font color=darkred>"%f"</font></font></font>, &Mesh_array[<font color=purple>num_obj-1</font>].fnormal[<font color=purple>i</font>].z); 				<font color=gray>//Converts z vertex value to int<br></font><br>				fscanf(infile, <font color=darkred><font color=darkred><font color=darkred>"%f"</font></font></font>, &Mesh_array[<font color=purple>num_obj-1</font>].fnormal[<font color=purple>i</font>].y); 				<font color=gray>//Converts y vertex value to int<br></font><br><br>				<font color=blue>for</font>(<font color=blue>int</font> loop=0; loop&lt;3; loop++)											<font color=gray>//Loop through vertex normals<br></font><br>				{<br>					fscanf(infile, <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"%s"</font></font></font></font></font></font>, &stream);										<font color=gray>//Skips "*MESH_VERTEXNORMAL"<br></font><br>					fscanf(infile, <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"%s"</font></font></font></font></font></font>, &stream);										<font color=gray>//Skips vertex normal index<br></font><br><br>					fscanf(infile, <font color=darkred><font color=darkred><font color=darkred>"%f"</font></font></font>, &Mesh_array[<font color=purple>num_obj-1</font>].vnormal[<font color=purple>i</font>].x);			<font color=gray>//Convert x value to int<br></font><br>					fscanf(infile, <font color=darkred><font color=darkred><font color=darkred>"%f"</font></font></font>, &Mesh_array[<font color=purple>num_obj-1</font>].vnormal[<font color=purple>i</font>].z);			<font color=gray>//Convert z value to int<br></font><br>					fscanf(infile, <font color=darkred><font color=darkred><font color=darkred>"%f"</font></font></font>, &Mesh_array[<font color=purple>num_obj-1</font>].vnormal[<font color=purple>i</font>].y);			<font color=gray>//Convert y value to int<br></font><br>				}<br>			}<br>		}<br>	}<br>}<br><br><br><font color=blue>void</font> Output_Obj()		<font color=gray>//Used strictly for debugging purposes<br></font><br>{<br>	outfile &lt;&lt; "OUTPUT_OBJ()<font color=darkred>" &lt;&lt; endl;<br>	for(int i=0; i&lt;num_obj; i++)<br>	{<br>		outfile &lt;&lt; "</font>New Object:<font color=darkred>" &lt;&lt; endl;<br>		outfile &lt;&lt; "</font>Vertices: <font color=darkred>" &lt;&lt; Mesh_array.num_vertex &lt;&lt; endl;<br>		for(int j=0; j&lt;Mesh_array.num_vertex; j++)<br>		{<br>			outfile &lt;&lt; Mesh_array.vertex[j].x &lt;&lt; "</font> <font color=darkred>";<br>			outfile &lt;&lt; Mesh_array.vertex[j].y &lt;&lt; "</font> <font color=darkred>";<br>			outfile &lt;&lt; Mesh_array.vertex[j].z &lt;&lt; "</font> <font color=darkred>" &lt;&lt; endl;<br>		}<br><br>		outfile &lt;&lt; endl &lt;&lt; "</font>Faces: <font color=darkred>" &lt;&lt; Mesh_array.num_faces &lt;&lt; endl;<br>		for(j=0; j&lt;Mesh_array.num_faces; j++)<br>		{<br>			outfile &lt;&lt; Mesh_array.face[j].x &lt;&lt; "</font> <font color=darkred>";<br>			outfile &lt;&lt; Mesh_array.face[j].y &lt;&lt; "</font> <font color=darkred>";<br>			outfile &lt;&lt; Mesh_array.face[j].z &lt;&lt; "</font> <font color=darkred>" &lt;&lt; endl;<br>		}<br>		outfile &lt;&lt; endl;<br>	}<br>}<br><br><br>GLuint Import(char *fname, GLuint map)<br>{<br>	outfile.open("</font>log.txt<font color=darkred>");<br><br>	if((infile = fopen(fname, "</font>r<font color=darkred>")) == NULL)					<font color=gray>//Opens data file<br></font><br>		outfile &lt;&lt; "</font>Could not open file " &lt;&lt; fname &lt;&lt; endl;		<font color=gray>//Outputs if file does not exist<br></font><br><br>	Mesh_array.clear();											<font color=gray>//Clears mesh array of all values<br></font><br>	map = NULL;													<font color=gray>//Clears map of all values<br></font><br><br>	Import_Obj();												<font color=gray>//Import the object<br></font><br><br>	<font color=blue>if</font>(Mat_array.size() &gt;= 0)									<font color=gray>//Checks if materials exist in file<br></font><br>		Import_Mat();											<font color=gray>//Import the materials<br></font><br><br>	fclose(infile);<br>	<font color=blue>return</font>	Draw_Triangles();<br>}<br></pre><!–ENDSCRIPT–> <br>i hope this didnt sound to rude or something like that.  Wildfire what i meant was with the code that i originally posted i thought that would be all i needed to give.  oh well thanks guys and girls (havent met many coder girls but im sure they exist).      <br><br><SPAN CLASS=editedby>[edited by - adam17 on August 20, 2003 5:27:21 PM]</SPAN>
quote:
Original post by adam17
struct MATERIAL
{
char Mat_name[sizeof(int)];
char Mat_file[sizeof(int)];
Vector3 rgb_Ambient;
Vector3 rgb_Diffuse;
Vector3 rgb_Specular;
float Transparency;
};



and Wildfire has it! take a look at the line where you declare Mat_file as a member of this struct. it''s declared as a char array (not quite what I ment by string, I was thinking of a stirng class). while an array is stored as a point in c/c++, static size arrays don''t have an assignment operator (if you do char*Mat_file the assignment operator copies the address, but then you''ll probably be using dynamic memory, either way, not what you want). to copy a char array (c-style string), as Wildfire said, use strcpy. but for this, stream has to be a char array, not a string class.

char*strcpy(char*destination,char*source);
i have given a lot of thought into this project and trying to get it to work. is there an easier way to convert between strings, char*, and char[]?? strcpy() requires a lot of changing and converting just to copy one little string. is there another way?
Advertisement
quote:

hope this didnt sound to rude or something like that. Wildfire what i meant was with the code that i originally posted i thought that would be all i needed to give. oh well thanks guys and girls (havent met many coder girls but im sure they exist).


Nah... I didn''t mean to shout at you like that... it was late and I was tired But it could''ve speed up the process of error-finding quite a bit.

Thanks for the credit Tricona, but Fruny was the first one to find out .
How do I set my laser printer on stun?
if(S_stream == "*BITMAP"){   fscanf(infile, "%s", &stream);   strcpy(Mat_array[num_mat].Mat_file,stream); // This should do it?}

Well, converting c-strings (both char* and char[]) into std::string should be pretty easy, I think you can use the assignement operator in either case.
The other way round is possible, but has many pitfalls... I''d pesonally use c-strings only when you really have to, and convert to std::string as soon as possible.
If you need to pass a c-string to a function, you can use the .data() operator of std::string, it''ll give you a const char*.
How do I set my laser printer on stun?
quote:
Original post by Wildfire
If you need to pass a c-string to a function, you can use the .data() operator of std::string, it''ll give you a const char*.

If you want to pass a C string somewhere, you should use c_str() instead if data(). The char * returned by data() is not guaranteed to be terminated by a zero if I remember correct.
Thanks for the info Brother Bob, I didn''t know that .
How do I set my laser printer on stun?

This topic is closed to new replies.

Advertisement