Theo Ekelmans
/
substring_demo
Simple substring demo using only the MBED default library
main.cpp
- Committer:
- ekelmans
- Date:
- 2012-01-10
- Revision:
- 0:97a47026da17
File content as of revision 0:97a47026da17:
// Simple substring demo using only the default MBED library // Theo@Ekelmans.com (NL) #include "mbed.h" Serial usbUART ( USBTX, USBRX ); void substring(char *s,char *d,int pos,int len) { //usage: substring(Source,Destination,pos,len); char *t; s=s+(pos-1); t=s+len; while (s!=t) { *d=*s; s++; d++; } *d='\0'; } int main() { usbUART.baud(115200); usbUART.printf("%c", 12); char Source[50]="working with strings is fun 0123456789 9876543210"; char Destination[50]; int pos,len; usbUART.printf("----------------------------------------------------------\r\n"); usbUART.printf(" substring demo \r\n"); usbUART.printf("----------------------------------------------------------\r\n"); usbUART.printf("source: %s\r\n", Source); usbUART.printf("----------------------------------------------------------\r\n"); printf("input the start position, tap enter, input length, tap enter "); scanf("%d%d",&pos,&len); printf("\n\n"); substring(Source,Destination,pos,len); printf("s= %s\n\r", Source); printf("d= %s\n\r", Destination); }