Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] Char array not taken as an argument type.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
sven3107
Expert Cheater
Reputation: 0

Joined: 04 Feb 2009
Posts: 118
Location: Belgium

PostPosted: Sun Nov 01, 2009 10:20 am    Post subject: [C++] Char array not taken as an argument type. Reply with quote

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
View user's profile Send private message Send e-mail MSN Messenger
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sun Nov 01, 2009 10:22 am    Post subject: Reply with quote

Code:
void WriteLine(char *Input)
{
   std::cout << Input << std::endl;
}

_________________
Back to top
View user's profile Send private message
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Sun Nov 01, 2009 10:24 am    Post subject: This post has 1 review(s) Reply with quote

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
View user's profile Send private message
sven3107
Expert Cheater
Reputation: 0

Joined: 04 Feb 2009
Posts: 118
Location: Belgium

PostPosted: Sun Nov 01, 2009 10:24 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail MSN Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sun Nov 01, 2009 12:48 pm    Post subject: Reply with quote

Since you're using C++ anyways: http://www.cplusplus.com/reference/string/string/
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites