Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


help needed when coverting char[] to char


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 da_cobra   Members   -  Reputation: 122

Like
Likes
Like

Posted 21 January 2002 - 07:08 AM

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

Sponsor:

#2 BeerNutts   Crossbones+   -  Reputation: 3018

Like
Likes
Like

Posted 21 January 2002 - 07:15 AM

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 [].

#3 da_cobra   Members   -  Reputation: 122

Like
Likes
Like

Posted 21 January 2002 - 08:49 PM

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

#4 da_cobra   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 January 2002 - 04:42 AM

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

#5 jacksonh   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 January 2002 - 04:48 AM

Try passing it like this


NewLog( &g_szClassName[0] )


also change NewLog to


NewLog( const char *str ) {


}


#6 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 22 January 2002 - 04:49 AM


char g_szClassName[] = "program template"
//Don''t make me constant!

void NewLog(const char *string)
{
}


Billy

#7 da_cobra   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 January 2002 - 10:58 PM

thanx I''ll try these solutions tonight

#8 da_cobra   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 January 2002 - 07:30 AM

thanx those last to solutions worked :D
thanx alot!!!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS