My code basically is to list ASCII codepoints of a string that is input, my following code is simple, here:
#include <iostream>
#include <string.h>
using namespace std;
int main() {
char str[20];
int result[20];
cin >> str;
for(int i = 0; i != strlen(str); i++) {
result[i] = (int)i;
}
for(int i = 0; i != 20; i++)
cout << result[i] << ", ";
}
when I run it, no matter what the input it outputs a pile of gibberish like undefined memory like so:
0, 1, 2, 3, 4, 5, 1, -1217349408, -1220040795, -1220041307, -1076427112, 134514781, -1218903292, 134519344, -1076427096, 134514004, -1217411568, 134519344, -1076427048, 134514681,
Am I missing something simple in how I append each integer to the array?
Just note this is a simple example, my input will not be larger than 20 characters.
EDIT Typo in my result.. cin>>result was cin>>str