I am super confused by this...
I was in the middle of an experiment, maybe is just that I am tired and I'm missing the obvious here (so facepalm is ready), but things are not working as expected, Image below (I'll also paste the code in case you want to try it out yourself)
#include <iostream>
#include <ostream>
using namespace std;
void to_lower(char* s)
{
char* text = s;
while (s != '\0')
{
char letter = *s;
if (letter > 'A' && letter < 'Z')
{
*s = 'a' + (letter - 'A');
}
s++;
}
cout << text << endl;
}
int main()
{
char* text = new char[12] {"Hello World"};
to_lower(text);
delete[] text;
return 0;
}
As you see in the debug image, the content of s[0] is 'l', but "char letter = *s;" is yelding a 'e'...what is this madness?! O_O
EDIT: forget what I asked above, I just understood that the yellow arrow means that the line isn't executed yet, I just had to step forward once
So, since that question turned useless I renamed this topic and I have a new question: my function enters an infinite loop.
Apparently the test "while (s != '\0')" is not good because when s points to '\0', the content of s is "" according to the debugger... so how do I test for '\0'?