I'm writing a program that takes in a user's string and prints out the occurrences of each letter. For some reason when I try to take the length of the string, it cuts out whatever is after a white space.
For example: you enter "hello world" and the length is 5, but if you entered "hello_world" the length is 11.
Also when trying to store the string to an int array it only stores whatever is before a white space. Anyone know what I'm doing wrong?
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
using namespace std;
int main()
{
//prototypes
void display_results(int a[]);
void compute_letter_count(int a[], string s);
//get user input for string
string usr_string;
cout << "Enter string: ";
cin >> usr_string;
//delete all non letter characters?
//get length of string
int length_string = usr_string.length();
cout << "the length is: " << length_string << endl;
//sort string in alphabetical order
sort(usr_string.begin(), usr_string.end());
//cout << usr_string;
//convert string to array of chars
const char *s = usr_string.c_str();
//create in array to convert char array to int array
int array[length_string];
//loop to change each index in usr_string to int in array
for (int i = 0; i < length_string; i++)
{
static_cast <int> (usr_string[i]);
array[i] = usr_string[i];
cout << array[i];
}
//cout << (int) usr_string[1];
return 0;
}
void display_results(int a[])
{
//for (int i = 0; i < 26; )
}
void compute_letter_count(int a[], string s)
{
//
}