|
-
Jun 27th, 2002, 01:46 PM
#1
Returning a char array doesn't work :(
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;
}
-
Jun 27th, 2002, 01:54 PM
#2
Frenzied Member
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
-
Jun 27th, 2002, 02:13 PM
#3
error C2234: '<Unknown>' : arrays of references are illegal
-
Jun 27th, 2002, 03:04 PM
#4
well i replace the & byt * and it worked,
Thx for the hint
-
Jun 27th, 2002, 03:05 PM
#5
Monday Morning Lunatic
Is this in C++? Why not just return a string object?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 27th, 2002, 03:25 PM
#6
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
-
Jun 27th, 2002, 03:28 PM
#7
Monday Morning Lunatic
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;
}
See www.bruceeckel.com (Thinking In C++) for more info on strings
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 27th, 2002, 03:40 PM
#8
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>
-
Jun 27th, 2002, 03:48 PM
#9
Monday Morning Lunatic
In a .cpp file, whack a "using namespace std;" just after the includes. In a header, use "std::string" rather than "string".
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 27th, 2002, 03:53 PM
#10
-
Jun 27th, 2002, 03:58 PM
#11
Monday Morning Lunatic
Most things are in there 
Strings are chapter 2 
(FYI I learnt most of this by progressively trashing my computer No, really, I actually wiped out Win 98 when my recursive folder search program went haywire )
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 27th, 2002, 04:05 PM
#12
-
Jun 27th, 2002, 04:12 PM
#13
Monday Morning Lunatic
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 refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 27th, 2002, 04:18 PM
#14
I will cry !!!!!
Code:
error C2228: left of '.length' must have class/struct/union type
C++ will make me crazy
and between I knew the -> but it did work that why I asked here
-
Jun 27th, 2002, 04:21 PM
#15
Monday Morning Lunatic
Hmm. Actually, you can't even initialise the array like that, arghh...
You need to do char *cPass = new char[sPass.length()];
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 27th, 2002, 04:46 PM
#16
error C2100: illegal indirection¸
I think I need to stop for tonight, I tryed so many thing and it still bugging grrrr
-
Jun 27th, 2002, 05:06 PM
#17
Lively Member
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...
-
Jul 10th, 2002, 06:11 PM
#18
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.)
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jul 11th, 2002, 10:05 AM
#19
Thx but STRING did the work well
-
Jul 11th, 2002, 11:19 AM
#20
Hyperactive Member
Originally posted by AlbafaN
either return a pointer to char array
You can't return a pointer to char array. bcos the char array will go out of scope when the function returns.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|