I tried to make a new char array and add to it chars. I wanted it to do by pointer. I know that is possible to move pointers in array by pointer arithmetic , so I wanted to use it. However it doesn't work and I don't know really why. Any idea why i can't use pointer arithemtic in array?
#include <math.h>
#include <iostream>
using namespace std;
void print (char *k){
while(*k!=0)cout<<*k++;
}
int main(){
int max = 128;
char* temp1 = new char[max];
*temp1 = 0;
char ch;
while (cin.get(ch)) {
if (ch=='\n') break;
*++temp1 = 0;
*--temp1 = ch;
temp1++;
}
print(temp1);
}