How to check my array for ""

I have an array of a typedef I made:

typedef unsigned char PegType;

When I debug the program, I see that some indices have the value '', which I think is a blank index (not even a white space). I want to be able to check for these occurrences and change the '' to a white space " ". How can I do this? I've tried:

1
2
3
if(myArrayOfPegType[i] == ""){
    myArrayOfPegType[i] == " ";
}


But the compiler tells me "Opperand types are incompatible ("char" and "const char*")"
Last edited on
a char cannot contain nothing. If you're seeing '', it could be 0 or some other unprintable char. If you can, cast it to integer to see what the numeric value is and compare to that.
Hi

you may use strlen to check whether the length of the target object zero is.

see http://www.cplusplus.com/reference/clibrary/cstring/strlen/

and remove one of the = operator from assigment ( cant use == in assigment) line 2


1
2
3
4
5
6
7
8
9
10
11
12

    // not this way 
     myArrayOfPegType[i] == " ";

   //but

          myArrayOfPegType[i] = ' '; 

    // or  this way
        myArrayOfPegType[i] = (char) 32;

}

hope it helps
Last edited on
As a little note, " " is really a const string of text. By typing std::cout << "blah" you are really printing out a constant pointer to char(string), because you cant modify what in the quotations(you would just create another one!). You are trying to assign a string " " to the vector CHAR. You would want to use ' '
Topic archived. No new replies allowed.