I am trying to convert char to wchar , but its not working !!the else case always executed in this code

char p[500];
 while(getline(inFile1, line))
  { 	
    //we read p from file that contain only one word "why"............for testing
    strcpy_s(p, 500, line.c_str());

    string search = p;
    const size_t newsize = 100;
    size_t origsize = strlen(search.c_str()) + 1;
    size_t convertedChars = 0;
    wchar_t wcstring[newsize];
    mbstowcs( wcstring, search.c_str(), newsize);
    wcscat_s(wcstring, L" (wchar_t *)");
    
    if(wcstring == L"why")
	        cout<<"Right conversion";
            else
	        cout<<"Wrong conversion";
char p[500] = nullptr
 while(getline(inFile1, line))
  { 	
    //we read p from file that contain only one word "why"............for testing
    strcpy_s(p, 500, line.c_str());

    string search = p;
    const size_t newsize = 100;
    size_t origsize = strlen(search.c_str()) + 1;
    size_t convertedChars = 0;
    wchar_t wcstring[newsize];
    mbstowcs( wcstring, search.c_str(), newsize);
    wcscat_s(wcstring, L" (wchar_t *)");
    
    if(wcstring == L"why")
	        cout<<"Right conversion";
            else
	        cout<<"Wrong conversion";
}

Edited 6 Years Ago by Orion2k: n/a

I did not get your point Do you mean that I should declare p like this

char p[500] = nullptr

ok its not working error nullptr not defined

and this is not working also

char *p;
      p = new char[500];
This article has been dead for over six months. Start a new discussion instead.