-->
Page 1 of 1

Problem withpointers

PostPosted: Wed May 18, 2016 11:49 am
by David Torres
Hi everyone!

I'm trying to make a project with Arduino IDE, but I can't make it works.

I have two variables:
Code: Select allchar* receivedbyserial;
char actualcharserial;


And I want to make this association:

Code: Select allif (Serial.available() > 0) {
      actualcharserial = Serial.read();
      *receivedbyserial = actualcharserial;
      receivedbyserial++;
    }


The code chrashes in the line *receivedbyserial = actualcharserial; and I don't know why...

Can you help me?
Thanks a lot!!

Re: Problem withpointers

PostPosted: Wed May 18, 2016 12:34 pm
by jcmvbkbc
David Torres wrote:
Code: Select allchar* receivedbyserial;
char actualcharserial;


Code: Select allif (Serial.available() > 0) {
      actualcharserial = Serial.read();
      *receivedbyserial = actualcharserial;
      receivedbyserial++;
    }


The code chrashes in the line *receivedbyserial = actualcharserial; and I don't know why...

You need to initialize receivedbyserial so that it points to a writable memory buffer before you can do this assignment.
And make sure it doesn't point past the buffer end in the process of receivedbyserial++-ing.

Re: Problem withpointers

PostPosted: Thu May 19, 2016 10:38 am
by David Torres
Thanks a lot! How I do that? Are there any guide with ESP88266 ESP01 directions?

Re: Problem withpointers

PostPosted: Mon Jul 18, 2016 1:35 am
by eriksl
This has nothing to do with esp8266, basic C knowledge.

It seems you don't want to use a pointer at all here.

Use something like:

char a;

a = function();