Can someone help me figure out what I am doing wrong here? I keep getting this error after I input:
The code:Code:Unhandled exception at 0x54AE350B (msvcp110d.dll) in Random.exe: 0xC0000005: Access violation writing location 0x0131CA21.
It builds without any errors. I am just trying to output the last character in the C-string. Am I doing this all wrong? D:Code:#include <iostream> #include <cstring> //Prototypes void lastChar(char *); int main() { const int LENGTH = 21; char *input = ""; std::cin.getline(input, LENGTH); lastChar(input); return 0; } void lastChar(char *str) { for(unsigned int count = 0; count < strlen(str); count++) { if(str[count] == '\0') { std::cout << str[count-1]; } else { str++; } } }




Reply With Quote