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";
}

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];
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.