Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Pass a string variable to a function.

Author
Message
Scarface
17
Years of Service
User Offline
Joined: 21st Oct 2006
Location:
Posted: 23rd Aug 2007 00:25 Edited at: 23rd Aug 2007 00:28
How do I pass a string to a function, I tried the most obvious way but it doesn't compile



Sorry for being such a noob, i'm trying really hard.

- Scarface
Karsten
17
Years of Service
User Offline
Joined: 24th Jan 2007
Location: N/A
Posted: 23rd Aug 2007 00:36 Edited at: 23rd Aug 2007 00:45
Hmm, what compile error do u get?


Quote: " if (dbLeftKey()) {

dbMoveObjectLeft(1, 2.0);
}
else if (dbRightKey()) {

dbMoveObjectRight(1, 2.0);
}
else if (dbUpKey()) {

dbMoveObjectUp(1, 2.0);
}
else if (dbDownKey()) {

dbMoveObjectDown(1, 2.0);"


I have noticed that the left key will always take priority with his method. You dont need else if.. just use if.
Scarface
17
Years of Service
User Offline
Joined: 21st Oct 2006
Location:
Posted: 23rd Aug 2007 00:37
cannot convert parameter 1 from 'char [255]' to 'char'

- Scarface
Karsten
17
Years of Service
User Offline
Joined: 24th Jan 2007
Location: N/A
Posted: 23rd Aug 2007 00:43 Edited at: 23rd Aug 2007 00:46
I believe that you have the right way of passing parameters but there is a type difference.

try...

char sX;
char sY;
char sZ;


rather than

Quote: "char sX[255];
char sY[255];
char sZ[255];"




See if it compiles.
Scarface
17
Years of Service
User Offline
Joined: 21st Oct 2006
Location:
Posted: 23rd Aug 2007 00:51
I think we're getting somewhere but I get error C2664: 'sprintf' : cannot convert parameter 1 from 'char' to 'char *' on the line sprintf, also do you know how to turn on line numbers?

- Scarface
Karsten
17
Years of Service
User Offline
Joined: 24th Jan 2007
Location: N/A
Posted: 23rd Aug 2007 00:57 Edited at: 23rd Aug 2007 01:01
sprintf... is that a function? I could not see it.. Again char* and char are different types... get rid of any * on any char in the sprintf function.

If that does not work.. try

char* sX;
char* sY;
char* sZ;

and add a * to all the other char(s)

rather than

Quote: "char sX;
char sY;
char sZ;"


Turn on line numbers? What IDE u using?
Scarface
17
Years of Service
User Offline
Joined: 21st Oct 2006
Location:
Posted: 23rd Aug 2007 01:01 Edited at: 23rd Aug 2007 01:02
I don't understand what you mean about getting rid of the * on any char in the sprintf function.

And i'm using Visual C++ 2005 Express Edition, it doesn't appear to have line numbers although the compiler always tells me what line the errors are on so it must be optional, but I can't find where to switch it on.

[Edit]
And the char* doesn't work, same error.

- Scarface
Karsten
17
Years of Service
User Offline
Joined: 24th Jan 2007
Location: N/A
Posted: 23rd Aug 2007 01:04 Edited at: 23rd Aug 2007 01:07
basically when u define a variable with

<type> <variable name>;

the type must match unless u learn how to convert them..

so

char* chrName;

is different to

char chrName;

so you wont be able to carry data from one variable to the other. (unless u convert it)
Scarface
17
Years of Service
User Offline
Joined: 21st Oct 2006
Location:
Posted: 23rd Aug 2007 01:06 Edited at: 23rd Aug 2007 01:08
Ok well I don't know how to convert them to make this work.

sprintf()

- Scarface
Karsten
17
Years of Service
User Offline
Joined: 24th Jan 2007
Location: N/A
Posted: 23rd Aug 2007 01:08 Edited at: 23rd Aug 2007 01:09
Oh.. I am not sure what the hell sprintf does. Soz but I dont think I can help/hinder you with this problem

I could be completely wrong about my idea of char* and char being different datatypes. We need an actual c++ programmer here because i rarely encounter this in c#

good luck!
Scarface
17
Years of Service
User Offline
Joined: 21st Oct 2006
Location:
Posted: 23rd Aug 2007 01:08 Edited at: 23rd Aug 2007 01:09
Link to function posted in my last post.

There must be some other more simple function to print a float as a string?

- Scarface
Karsten
17
Years of Service
User Offline
Joined: 24th Jan 2007
Location: N/A
Posted: 23rd Aug 2007 01:16 Edited at: 23rd Aug 2007 01:20
instead of char...

can u not use string?

string sX;
string sY;
string sZ;

if u get an error try String not string

Remember to replace all the char in the perameters with string too.

I rarely use char. String is a lot easier.

may need #include <string> at the top.
Scarface
17
Years of Service
User Offline
Joined: 21st Oct 2006
Location:
Posted: 23rd Aug 2007 01:20
'string' is what i'd normally use in the other C based language I use, however it doesn't seem to function in my compiler, it doesn't turn blue like a variable should.

I am doing away with the print screen coordinates now I don't really need them, they were just a reference for me to see how vector positions work.

Thanks for the help, plenty more Qs coming soon

- Scarface
Karsten
17
Years of Service
User Offline
Joined: 24th Jan 2007
Location: N/A
Posted: 23rd Aug 2007 01:22
lol KK. And I'll be ready to give really crap answers to ur Q's haha.

Good luck with the gdk.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 23rd Aug 2007 01:59
Your problem is in the way you declarate your 'CalculateMovement' function.

Try this:


Aside from that, I'm not sure why you are passing in the strings that are set and used only in the CalculateMovement. Unless you intend, somewhere down the road, to use them by whatever calls CalculateMovement.

By the way, sprintf is a standard C function and definitely a preferred way to build strings for display. You can combine strings and numbers to your heart's content. Here are some links that give some information on it:
http://www.cppreference.com/stdio/sprintf.html
http://www.cplusplus.com/reference/clibrary/cstdio/sprintf.html

Cheers,
Ancient Lady

Cheers,
Ancient Lady

Login to post a reply

Server time is: 2024-09-29 01:13:11
Your offset time is: 2024-09-29 01:13:11