Click here to Skip to main content
15,908,675 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have one array of WCHAR is like this

WCHAR Path[256]; so I'm passing this array in my function getpath(Path) and It's filling the value in path like this: //device/systemName/

So I want to get only device from above string

My code is here
C++
WCHAR *pDevName;

int i = 0;
int j = 0;   
while(Path[i] != NULL){ 
    if(0 ==(wcscmp(Path, L"/")))
    {
        
        //i = i + 2;
        ++i;
        continue;
    }
    
    else
    {
        pDevName[j] = Path[i];
        
        ++i;
        ++j;
        if (0 == wcscmp(Path, L"/")){
            break;
        }
    }

My code is getting compiled but It's not returning for me device from WCHAR array. It's returing //devicename/systemName/. which is coming from pDevName.

I have doubt over my comparison on wcscmp(). SO my question is how to compare / with remaining wchar array value.

P.S. : devicename could be anything like c: or xyz.

Please help It's very urgent for me.
Posted
Updated 9-Jul-13 21:57pm
v2

1 solution

Look at the documentation for wcscmp()[^]; your code will never work because you are comparing a full path with a single character. You would be better using something like wcschr()[^] to find the separator characters, or wcstok_s()[^] to split your path into its constituent parts.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900