Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem mbed
Fork of SDFileSystem_HelloWorld by
main.cpp@2:886ae0153478, 2017-10-05 (annotated)
- Committer:
- martinsimpson
- Date:
- Thu Oct 05 10:49:22 2017 +0000
- Revision:
- 2:886ae0153478
- Parent:
- 0:bdbd3d6fc5d5
- Child:
- 4:73d5d4c507c9
wrk
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mbed_official | 0:bdbd3d6fc5d5 | 1 | #include "mbed.h" |
| mbed_official | 0:bdbd3d6fc5d5 | 2 | #include "SDFileSystem.h" |
| mbed_official | 0:bdbd3d6fc5d5 | 3 | |
| martinsimpson | 2:886ae0153478 | 4 | SDFileSystem sd(D11, D12, D13, D10, "sd"); // the pinout on the mbed Cool Components workshop board |
| martinsimpson | 2:886ae0153478 | 5 | |
| martinsimpson | 2:886ae0153478 | 6 | char myStr[128]; |
| martinsimpson | 2:886ae0153478 | 7 | |
| mbed_official | 0:bdbd3d6fc5d5 | 8 | int main() { |
| martinsimpson | 2:886ae0153478 | 9 | printf("Start to write!\n"); |
| mbed_official | 0:bdbd3d6fc5d5 | 10 | |
| mbed_official | 0:bdbd3d6fc5d5 | 11 | mkdir("/sd/mydir", 0777); |
| mbed_official | 0:bdbd3d6fc5d5 | 12 | |
| mbed_official | 0:bdbd3d6fc5d5 | 13 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); |
| mbed_official | 0:bdbd3d6fc5d5 | 14 | if(fp == NULL) { |
| mbed_official | 0:bdbd3d6fc5d5 | 15 | error("Could not open file for write\n"); |
| mbed_official | 0:bdbd3d6fc5d5 | 16 | } |
| martinsimpson | 2:886ae0153478 | 17 | fprintf(fp, "Hello World!"); |
| martinsimpson | 2:886ae0153478 | 18 | fprintf(fp, "This is a second line"); |
| martinsimpson | 2:886ae0153478 | 19 | fprintf(fp, "and now a third line"); |
| mbed_official | 0:bdbd3d6fc5d5 | 20 | fclose(fp); |
| mbed_official | 0:bdbd3d6fc5d5 | 21 | |
| martinsimpson | 2:886ae0153478 | 22 | printf("Finished writing and closed file\n"); |
| martinsimpson | 2:886ae0153478 | 23 | |
| martinsimpson | 2:886ae0153478 | 24 | FILE *fp1 = fopen("/sd/mydir/sdtest.txt", "r"); |
| martinsimpson | 2:886ae0153478 | 25 | //fscanf(fp1, "%s", myStr); |
| martinsimpson | 2:886ae0153478 | 26 | fgets(myStr, 12, fp1); |
| martinsimpson | 2:886ae0153478 | 27 | printf("\t%s\n\r",myStr); |
| martinsimpson | 2:886ae0153478 | 28 | fclose(fp1); |
| mbed_official | 0:bdbd3d6fc5d5 | 29 | } |
