AnsweredAssumed Answered

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

Question asked by bao.hoang on Feb 20, 2013
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:
Code 

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

Outcomes