Lab3-01_save_read_the_number_lite
Dependencies: mbed HEPTA_CDH_lite
Diff: main.cpp
- Revision:
- 2:35a16011d7ce
- Parent:
- 1:ddac5ec89167
--- a/main.cpp Wed Aug 11 03:50:32 2021 +0000 +++ b/main.cpp Fri Aug 20 12:06:48 2021 +0000 @@ -4,16 +4,22 @@ Serial pc(USBTX,USBRX,9600); int main() { - pc.printf("Hello World!\n"); - + char str[100]; + pc.printf("Hello World!\r\n"); mkdir("/sd/mydir", 0777); - FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); if(fp == NULL) { error("Could not open file for write\r\n"); } - fprintf(fp, "Hello my name is HEPTA\r\n"); + for(int i=0; i<10; i++){ + fprintf(fp,"decimal number = %d, floating-point number = %f\r\n",i,i*1.5); + } fclose(fp); - + fp = fopen("/sd/mydir/sdtest.txt","r"); + for(int i = 0; i < 10; i++) { + fgets(str,100,fp); + pc.puts(str); + } + fclose(fp); pc.printf("Goodbye World!\r\n"); } \ No newline at end of file