cancel
Showing results for 
Search instead for 
Did you mean: 

[Help]Error read 2 file .txt successive from sd card to use the library fatfs

hoanghuybao
Associate
Posted on February 20, 2013 at 08:56

Hi everyone 

When read 2 files .txt consecutive , see error.Error caused as a result of readings of the 2nd file insert strange characters.

[IMG]https://dl.dropbox.com/u/13524300/armvn/loi1.jpg[/IMG]

In the image above to read 2 file. txt is sms1.txt and account.txt

When reading the file sms1.txt and then read file account.txt, results of read of files account.txt insert them strange characters: ''do ~''.

//Readfile txt

char*ReadFileTxt(char *name)

{

            char *result;

            int       totalBytesRead= 0;

           

            printf(''\n name =%s'',name);

           

            f_mount(0,&fsa);

            res = f_open(&fsrc,name,FA_READ);

            for (;;) {

                        res = f_read(&fsrc,buffer, sizeof(buffer), &br);           /*Read a chunk of file */

                        if (res || !br)  break;                                    /*Error or end of file */

                        //totalReadTimes++;

                        totalBytesRead+=br;         

            }

           

  /* IMPORTANT */

            result= (char*)malloc((totalBytesRead+1)* sizeof(char));

            strncpy(result,buffer,totalBytesRead);    

            printf(''\n body =%s'',result);

            f_close(&fsrc);

            printf(''\n Bytes Read =%d'',totalBytesRead);

  return result;

}

code full:

https://dl.dropbox.com/u/13524300/armvn/SD%20Card%20%28SPI%202%29_Error.rar

Link youtube error:http://www.youtube.com/watch?v=M5_9g3Cufrw
0 REPLIES 0