Good day! When parsing pointers in C, I encountered one problem:
#include <iostream> #include <cstdlib> #include <cmath> #include <cstdio> using namespace std; int main () { char* str1 = NULL; str1 = (char*)malloc(sizeof(char) * 20); cin >> *str1; for (int i = 0; i < 20; i++) cout << str1[i]; }
When you enter any characters, then only the first character of the line is the same when outputting, everything else is displayed not what was entered (some kind of nonsense is output)!
I understand that everything can be done 987654 times easier, but I want to deal with this case.
How to make it so that the char string is displayed normally?
cin
norcstdlib
nor thenamespace std
will appear. This means that (1) you use a compiler that supports both (MSVC?), And (2) do not know the difference between these languages. - VladD pm