View previous topic :: View next topic |
Author |
Message |
sven3107 Expert Cheater
Reputation: 0
Joined: 04 Feb 2009 Posts: 118 Location: Belgium
|
Posted: Sun Nov 01, 2009 10:20 am Post subject: [C++] Char array not taken as an argument type. |
|
|
Right, I'm doing some basic functions with consoles, but for some reason I get syntax errors when I use this declaration.
Code: | void WriteLine(char[] Input)
{
std::cout<<Input<<std::endl;
} |
And it returns this error: "error C2146: syntax error : missing ')' before identifier 'Input'"
However, using a fixed size array works just fine.
Code: | void WriteLine(char Input[80])
{
std::cout<<Input<<std::endl;
} |
Returns no errors.
So my question is: How would I use char[] as input type, since it usually works just fine?
|
|
Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Nov 01, 2009 10:22 am Post subject: |
|
|
Code: | void WriteLine(char *Input)
{
std::cout << Input << std::endl;
} |
_________________
|
|
Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Sun Nov 01, 2009 10:24 am Post subject: |
|
|
What you would need to do is pass a reference to the array, so as your argument type ([] is invalid and can't be used) you can make it a pointer by prefixing the variable name with a *.
Code: |
void func(char *array)
{
array[0] = '\0';
}
|
|
|
Back to top |
|
 |
sven3107 Expert Cheater
Reputation: 0
Joined: 04 Feb 2009 Posts: 118 Location: Belgium
|
Posted: Sun Nov 01, 2009 10:24 am Post subject: |
|
|
Thanks, but could you explain how using a pointer helps solve the problem?
I don't really like to paste code without understanding the full function.
EDIT: Never mind, sorta slow reply, so I didn't see the second reply.
Thanks.
|
|
Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
|
Back to top |
|
 |
|