programme GPS pour ERS4

Dependencies:   mbed

Fork of GPS_IUT_Nice by tito tito

getline.cpp

Committer:
pierrick
Date:
2016-03-11
Revision:
2:addb687a4e73
Parent:
1:f24af888e699

File content as of revision 2:addb687a4e73:

#include "mbed.h"
// receive a line from a stream, allowing backspace editing,
// and checking for buffer overflow. Terminates on either a \n or \r.
size_t getline(Stream &s, char *buf, size_t bufsize)
{
    char c;
    size_t receivedChars = 0;
    for(;;)
    {
        c = s.getc();
        if (c == '\r' || c == '\n')
            break;
        s.putc(c);
        if (c == '\b')
        {
            if (receivedChars > 0)
            {
                buf--;
                receivedChars--;
            }
        }
        else if (receivedChars < bufsize - 1)
        {
            *buf++ = c;
            receivedChars++;
        }
    }
    *buf++ = 0;
    s.putc('\n');
    s.putc('\r');
    return receivedChars;
}