View previous topic :: View next topic |
Author |
Message |
Futterama
Joined: 17 Oct 2005 Posts: 98
|
Pointer to the middle of an array |
Posted: Fri Aug 01, 2014 6:13 am |
|
|
Hi forum,
I have a char array as ring buffer for receiving serial data.
I'm trying to locate some text in the buffer, so I would compare it to another array of char. I would use the strcmp function for comparison, and it takes pointers to the arrays, which is fine. But I don't want to start comparing from the beginning of the ring buffer array, so how do I create a pointer to someplace in the middle of the array?
Best regards,
Martin |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri Aug 01, 2014 6:38 am |
|
|
POST your code!!
this is a practical forum -
not a blind debating society |
|
|
Futterama
Joined: 17 Oct 2005 Posts: 98
|
|
Posted: Fri Aug 01, 2014 6:47 am |
|
|
I just solved it myself, actually just by reading some regular C code example from here: http://www.eskimo.com/~scs/cclass/notes/sx10b.html
Code: | char array[] = {"This is a test"}; // The array with text data
char *ptr; // The pointer
ptr = &array[5]; // Set pointer to point at somewhere inside the array
printf("%c", *ptr); // Print the char from the array which the pointer points to
|
Sweet :-) |
|
|
|