i just want to calculate the length of char*,so i write
but the error “there is no cast from const char * to int”?Code:int len(char* str) { int i = 0; while (*str != "/0") { ++i; ++str; } return i; }
how to deal with it?
i just want to calculate the length of char*,so i write
but the error “there is no cast from const char * to int”?Code:int len(char* str) { int i = 0; while (*str != "/0") { ++i; ++str; } return i; }
how to deal with it?
By realising that "/0" is not the same thing as '\0'
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
ok , that's the thing ,i correct it ,thank you !
That mistake is way too common. For the same reason you assume linux users get confused about this, I could blame people on the internet in general. The internet uses the same directory marker as linux does.