problem 7 for HW 2
Dependencies: SDFileSystem mbed
Fork of SDFileSystem_HelloWorld by
main.cpp@1:d8f90021eb1a, 2015-02-18 (annotated)
- Committer:
- lzzcd001
- Date:
- Wed Feb 18 14:52:56 2015 +0000
- Revision:
- 1:d8f90021eb1a
- Parent:
- 0:bdbd3d6fc5d5
problem 7 for HW 2
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" |
lzzcd001 | 1:d8f90021eb1a | 3 | #include <string> |
mbed_official | 0:bdbd3d6fc5d5 | 4 | |
mbed_official | 0:bdbd3d6fc5d5 | 5 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board |
mbed_official | 0:bdbd3d6fc5d5 | 6 | |
mbed_official | 0:bdbd3d6fc5d5 | 7 | int main() { |
mbed_official | 0:bdbd3d6fc5d5 | 8 | printf("Hello World!\n"); |
lzzcd001 | 1:d8f90021eb1a | 9 | //for(i=0; 1; i++) if(fgetc(file) == EOF) break; |
lzzcd001 | 1:d8f90021eb1a | 10 | |
lzzcd001 | 1:d8f90021eb1a | 11 | //fseek(file, 0, SEEK_SET); |
lzzcd001 | 1:d8f90021eb1a | 12 | |
lzzcd001 | 1:d8f90021eb1a | 13 | char *out = (char*) malloc(sizeof(char) * 100+1); |
mbed_official | 0:bdbd3d6fc5d5 | 14 | mkdir("/sd/mydir", 0777); |
mbed_official | 0:bdbd3d6fc5d5 | 15 | |
mbed_official | 0:bdbd3d6fc5d5 | 16 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); |
mbed_official | 0:bdbd3d6fc5d5 | 17 | if(fp == NULL) { |
mbed_official | 0:bdbd3d6fc5d5 | 18 | error("Could not open file for write\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 19 | } |
lzzcd001 | 1:d8f90021eb1a | 20 | fprintf(fp, "Hello fun SD Card World!"); |
lzzcd001 | 1:d8f90021eb1a | 21 | |
lzzcd001 | 1:d8f90021eb1a | 22 | FILE *fpd = fopen("/sd/sdtest.txt", "r"); |
lzzcd001 | 1:d8f90021eb1a | 23 | if(fp == NULL) { |
lzzcd001 | 1:d8f90021eb1a | 24 | error("Could not open file for write\n"); |
lzzcd001 | 1:d8f90021eb1a | 25 | } |
lzzcd001 | 1:d8f90021eb1a | 26 | fscanf(fpd,"%s",out); |
lzzcd001 | 1:d8f90021eb1a | 27 | |
lzzcd001 | 1:d8f90021eb1a | 28 | if(fp == NULL) { |
lzzcd001 | 1:d8f90021eb1a | 29 | error("Could not open file for write\n"); |
lzzcd001 | 1:d8f90021eb1a | 30 | } |
lzzcd001 | 1:d8f90021eb1a | 31 | fprintf(fp, out); |
mbed_official | 0:bdbd3d6fc5d5 | 32 | fclose(fp); |
lzzcd001 | 1:d8f90021eb1a | 33 | fclose(fpd); |
mbed_official | 0:bdbd3d6fc5d5 | 34 | printf("Goodbye World!\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 35 | } |