help needed when coverting char[] to char

Started by
6 comments, last by da_cobra 22 years, 3 months ago
I''m trying to pass on a string to a function using a pointer but I keep on getting this error cannot convert parameter 1 from ''const char [17]'' to ''char'' and I just can''t figure out what I''m doing wrong I have the following code

const char g_szClassName[] = "program template" ;

NewLog(g_szClassName) ;

void NewLog(char *string)
{
	SYSTEMTIME st ;
	GetSystemTime (&st) ;
	ofstream file ("LogFile.e2x") ;
	file << "Log file for " << string << "\n" 
		 <<	"-----------------------------" << "\n\n" 
		 << "Created on " << st.wDay << "/" 
		 << st.wMonth << "/" << st.wYear << "\n" ;

	file.close() ;
} // end of NewLog() 
 
what am I doing wrong I already tried so many things and still haven''t found my fault yet
Advertisement
Why are you declaring it const? If you don''t want it changed, then change you''re parameter to const char [], otherwise, the compiler assumes, if you''re passing a const char [] to a char *, then it makes it not const anymore, which is a no-no.

So, either don''t make it const, or change the parameter to const char [].

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

well I tried to make my parameter as const char[]
and that didn''t work

but i''ll try to remove the const before the declaration tonight
maybe that''ll work

thanx for the reply
nope that didn''t work
but maybe I should give the exact error and that is

error C2664: ''NewLog'' : cannot convert parameter 1 from ''char [17]'' to ''char''
This conversion requires a reinterpret_cast, a C-style cast or function-style cast

and yes I already tried char[17] in my function parameter
Try passing it like this

NewLog( &g_szClassName[0] ) 


also change NewLog to

NewLog( const char *str ) {} 
char g_szClassName[] = "program template"//Don''t make me constant!void NewLog(const char *string){} 


Billy
thanx I''ll try these solutions tonight
thanx those last to solutions worked :D
thanx alot!!!

This topic is closed to new replies.

Advertisement