Can someone please help me with what is causing this program to error when it runs? It compiles and the window opens but when I type a sentence and press enter I get an error message and have to abort. I first made the program with the first char array in main as char cstr[SIZE] = "Mary Had a Little Lamb"; so that I would not have to type something in everytime I ran the program for a test. Initially the program worked this way. When the programming was completed I then changed main to
1 2 3
char cstr[SIZE];
cin.getline(cstr, SIZE);
and I am now receiving this error:
1 2 3 4 5 6
Debug Assertion Failed.
Line: 56
Expression: c >= -1 && c <= 255
For information on how your program... yada yada.
Okay I found the way to correct it is to change the count < SIZE part of the for loops to count < strlen(str) but I don't understand why? I declared SIZE as a global variable and I can't see any other reason as to why it wouldn't work. Any one else know?
cin.getline(cstr, SIZE); User enters: Hello
Though the size of the array is 50, only five characters have been entered; the array contains these five characters plus a null terminating character at the beginning. The remaining 44 characters are uninitialised and should not be used.
The name reverse does not suggest toggling the case: maybe rename it as reverse_case?