c++ - Remove/ignore everything except characters in a Cstring -
I'm trying to read about 100 characters in some text and then it's empty space, numbers, special characters I'm trying to hide from the bar. , e.t.c. I was thinking about ways to go about doing this, but I think I should forget about the seastring I know, so should I forget. I was originally trying to settle in the original characters and trying to copy them into a new string, but 1. I do not know how to write it, so my compiler does not hate me 2. I I'm pretty sure that I do not want to have an empty place in the new, stripped string (I'm pretty sure my code is due to this so far, if it also works).
char * userText = ""; Char * justCharTxt; Cout & lt; & Lt; "Enter text:" & lt; & Lt; Endl; Cin.getline (user text, STRING_SIZE); For (Int i = 0; I & lt; strlen (Usertext); I ++) {if (((Usertext [ii]> = 'A') & amp; (Usertext [i] & lt ; = 'Z')) || ((Usertext [ii]> = 'A') & amp; amp; (Usertext [i] & lt; = 'Z')) * justCharTxt = userTxt [i] ; } Some guidance on this issue would be horrible. Thanks!
- You need to reduce your strings, that is, reserve buffer
- You have to increase the distance pointer.
#include & lt; Iostream & gt; using namespace std; int main () {int const STRING_SIZE = 20; Four user text [STRING_SIZE * 2] = ""; Char just carttext [STRING_SIZE] = ""; char * txtPt = justCharTxt; Cout & lt; & Lt; "Enter text:" & lt; & Lt; Endl; Cin.getline (user text, STRING_SIZE); For (Int i = 0; I & lt; strlen (Usertext); I ++) {if (((Usertext [ii]> = 'A') & amp; (Usertext [i] & lt ; = 'Z')) || ((Usertext [ii]> = 'A') & amp; amp; (Usertext [i] & lt; = 'Z')) * * (TSTTPT ++) = Usertext [I]; } cout & lt; & Lt; Just CHTTX & lt; & Lt; Endl; Return 0; } $ clang ++ justit.cpp $ ./a.out enter text: ab123 a aba
Comments
Post a Comment