I get no response when:
if ( c != '\n' || c != '\r')
How to I check if the input buffer is full?
You know the buffer is full when your index variable equals the length of the buffer.
Your logic checking for end-of-line is a bit tortuous because you're checking for characters NOT being end of line, so in that case you would need to use 'and' rather than' not. It would be much simplrer if you inverted the logic like this:
const int MAX_LEN = 20;
char buffer[MAX_LEN+1]; // allow space for the terminating null
int length = 0;
if ( c == '\n' || c == '\r')
// end-of-line received
// process content of buffer, if any
if(length > 0)
length = 0;
// not end-of-line
if(length < MAX_LEN)
buffer[length++] = c;
buffer[length] = '\0';
You'll notice I renamed 'i' to 'length'; it's common to use single letter variables as local loop counters and your global 'i' would clash with any local variables of the same name.