Theo Ekelmans
/
substring_demo
Simple substring demo using only the MBED default library
Revision 0:97a47026da17, committed 2012-01-10
- Comitter:
- ekelmans
- Date:
- Tue Jan 10 21:58:57 2012 +0000
- Commit message:
- V 1.0
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 97a47026da17 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jan 10 21:58:57 2012 +0000 @@ -0,0 +1,46 @@ +// 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); + +}
diff -r 000000000000 -r 97a47026da17 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Jan 10 21:58:57 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/3b05dd009342