- you need to init your strings, i.e., reserve a buffer
- you need to increment the dest pointer.
#include <iostream> using namespace std;
int main(){
int const STRING_SIZE=20;
char userText[STRING_SIZE*2]="";
char justCharTxt[STRING_SIZE]="";
char * txtPt = justCharTxt;
cout << "Enter text: " << endl;
cin.getline(userText, STRING_SIZE);
for (int i = 0; i < strlen(userText); i++){
if (((userText[i] >= 'a') && (userText[i] <= 'z')) ||
((userText[i] >= 'A') && (userText[i] <= 'Z')))
*(txtPt++)= userText[i];
}
cout << justCharTxt << endl;
return 0;
}
$ clang++ justit.cpp $ ./a.out Enter text: ab123 a aba