Assign string to TCHAR

I'm having getting error messages trying to do the following:

extern TCHAR ext_app_name[MAX_PATH];
// Try to overwrite the value
ext_app_name = _T("http://www.myurl.com/home.html");

But I'm getting the following error message:

error: incompatible types in assignment of `const wchar_t[72]'  to `TCHAR[260]'

Thanks!
LVL 1
mybluegrassAsked:
Who is Participating?
 
cupConnect With a Mentor Commented:
For the assignment, use

_tcscpy (ext_app, _T("whatever"));
0
 
evilrixSenior Software Engineer (Avast)Commented:
ext_app_name is an array not a pointer so you need to copy the string into the array not assign it like a pointer.
0
 
mybluegrassAuthor Commented:
In the code, how come this line works fine:

TCHAR ext_app[MAX_PATH*4]=_T("\"");
 _tcscat(ext_app,ext_app_name);

Doesn't ext_app have the same type as ext_app_name? If _T("\"") can be assigned to ext_app, I thought a regular string can be assigned to ext_app_name as well.

Thanks!

Ming
0
 
evilrixSenior Software Engineer (Avast)Commented:
That works because you're doing it at definition time. That's the only time you are allowed to assign like that. See the difference between...

TCHAR ext_app[MAX_PATH*4]=_T("\"");

and

extern TCHAR ext_app_name[MAX_PATH];
ext_app_name = _T("http://www.myurl.com/home.html");

In the 2nd case you are not doing the assignment on definition.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.