To call Azure Marketplace Translation (and Speech) service

Dependencies:   EthernetInterface-FRDM HTTPClient-SSL R_BSP SDFileSystem TLV320_RBSP USBHost mbed-rtos mbed-src

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers getline.cpp Source File

getline.cpp

00001 
00002 #include <mbed.h>
00003 
00004 int getline(char *prompt, char *buff, int size)
00005 {
00006     int sz ;
00007     
00008     printf("%s", prompt) ;
00009     for(sz = 0 ;  (sz < size) && ((*buff = getchar()) != '\r'); sz++, buff++) {
00010         putchar(*buff) ;
00011         if(*buff == '\\') {
00012             if(++sz >= size)break ;
00013             *buff = getchar() ;
00014             putchar(*buff) ;
00015             switch(*buff) {
00016                 case 'n' :
00017                     *buff = '\n' ;
00018                     break ;
00019                 case 'r' :
00020                     *buff = '\r' ;
00021                     break ;
00022                 case 't' :
00023                     *buff = '\t' ;
00024                     break ;
00025                 case '\\':
00026                     *buff = '\\' ;
00027                     break ;
00028                 default:
00029                     buff[1] = buff[0] ;
00030                     buff[0] = '\\' ;
00031                     buff++ ;
00032             }
00033         } else if(*buff == '\b') {
00034             if(sz >= 2) {
00035                 buff-=2 ;
00036                 sz-=2;
00037             }
00038         }
00039     } ;
00040     putchar('\n') ;
00041     *buff = '\0' ;
00042     return sz ;
00043 }