why that doesn't work :
Code:char[] PasswordMaker()
{
char cPass[20];
char cChar;
for (int i = 0 ; i < 20;i++ )
{
if ((cChar = getch()) != '\n')
cPass[i++] = cChar;
else
break;
}
return cPass;
}
Printable View
why that doesn't work :
Code:char[] PasswordMaker()
{
char cPass[20];
char cChar;
for (int i = 0 ; i < 20;i++ )
{
if ((cChar = getch()) != '\n')
cPass[i++] = cChar;
else
break;
}
return cPass;
}
I've never seen char [] as a returntype...try making a call by reference parameter...
void PasswordMaker(char &mystring[20])
so now whatever you enter into the function is what gets changed :D
error C2234: '<Unknown>' : arrays of references are illegal
:(
well i replace the & byt * and it worked,
Thx for the hint :)
Is this in C++? Why not just return a string object?
well I never played with String in C++ and I can not figure how to use the keyboard input to put stuff in String so I do not touch to String, want to learn me ? In my book they do not talk about String :(
See www.bruceeckel.com (Thinking In C++) for more info on strings :)Code:#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "What is your name? " << flush;
string nm;
getline(cin, nm);
cout << endl << "Hello " << nm << "!" << endl;
return 0;
}
Thx you, it worked once and when I tryed to implement it to my function i got now 22 errors and they look like :
error C2065: 'string' : undeclared identifier
and I do not have a clue why, because I have the include <string>
In a .cpp file, whack a "using namespace std;" just after the includes. In a header, use "std::string" rather than "string".
How you know that ? Can you tell me if it's in : Thinking In C++ ?
I need to know all that stuff !
And a big thank you for your help :):):):):):)
Most things are in there ;)
Strings are chapter 2 :p
(FYI I learnt most of this by progressively trashing my computer :D No, really, I actually wiped out Win 98 when my recursive folder search program went haywire :eek:)
Coooool :)
But one more thing before I go eat ;)
I have searched in my VisualC++ help and I have found something about the string library. I know that it have a length() function but I can not access it in my header file (in a function)
here is a little piece of code :
If you can tell me why when I add the dot after the sPass I do not see all String option maybe it will solve the error (error C2057: expected constant expression)Code:void utility::PasswordMaker(std::string *sPass)
{
char cChar;
char cPass[sPass.length()];
And what I want to do is to be able to write at a speacific place in the string so I put back my String in a char[] and later will put back in the String, I know it's not the best way but I want to try this one for the moment. So if you can help me to tell me why it do that I will appreaciate and if you see an other solution feel free to suggest it. I think this weekend I will go buy your good book :)
You're passing a pointer so you need to use ->.
In this situation, I'd recommend a const reference:Code:void utility::PasswordMaker(const std::string &sPass)
{
char cChar;
char cPass[sPass.length()];
I will cry !!!!!
C++ will make me crazyCode:error C2228: left of '.length' must have class/struct/union type
and between I knew the -> but it did work that why I asked here :)
Hmm. Actually, you can't even initialise the array like that, arghh...
You need to do char *cPass = new char[sPass.length()];
error C2100: illegal indirection¸
I think I need to stop for tonight, I tryed so many thing and it still bugging grrrr
either return a pointer to char array, or have one of your functions param be a pointer to a char array you declared outside the function and modify it in the function threw the pointer...
about strings....
there's also the CString class...
No, CString is not an option here. It's MFC only, and I don't think it has a place in what DaoK is doing here.
If you post the code we could try finding the errors. (If you haven't already done, it's been a while.)
Thx but STRING did the work well :)
You can't return a pointer to char array. bcos the char array will go out of scope when the function returns.Quote:
Originally posted by AlbafaN
either return a pointer to char array