Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

assign string literal to char array 1

Status
Not open for further replies.

javaguy1

Programmer
Joined
May 14, 2003
Messages
136
Location
US
in the code below, i get the following compile error at the last line.
C:\My Courses\Cs133u\chapter5\Cryptography\Cryptography.cpp(32) : error C2106: '=' : left operand must be l-value
if i change char message[27] to *message, it compiles, but the program commits an illegal act at runtime. thats why i used a char array in the first place (so i could specify the size). why am i getting this compile time error?

void main()
{
char password[11];
char verify[11];
char message[27] = "Enter your password ";

getPassword(password, verify, message);
message = "Enter your password again ";
 
Take a look at the Complete Layman's Guide to Pointers FAQ

faq116-2914

-pete
 
nice tutorial, but i already knew all that and it didnt answer my question.
 
i suppose i could just have a seperate variable for each message, but i was trying to reuse the one i had and dont need anymore.
 
>> why am i getting this compile time error?
Code:
strcpy(message,"Enter your password again ");

-pete
 
thanks for the answer. as it turns out there was no need to pass the message to the function to begin with, therefore no need for that variable. i just sent the messages using cout before the function calls. however i did learn something interesting. when i ran it i still got a runtime error about illegal act. it turns out i was passing a char arrray that wasnt a string(didnt have a null char at the end) to a function that passed it to strlen() :+/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top