I’m learning to use the write function and am trying to print only a part of a buffer array of chars. So it looks like this:
char *tempChar;
char *buf;
buf=&tempChar;
read(0, buf, 10);
write(1, [???], 1);
I thought about putting buf[3] where the [???] is, but that didn’t work.
I also thought about using tempChar[3], but that didn’t work either.
Any ideas? Thanks so much.
You would use
buf + 3. This is pointer arithmetic. It takes buf and gives you a new pointer 3 characters down.buf[3]is equivalent to*(buf + 3). Note the unwanted dereference.As another note:
is probably not right.
That assigns the address of the tempChar variable to buf, which is probably not what you want.