Note that there are some explanatory texts on larger screens.

plurals
  1. POCopying a string from a pointer to a string
    primarykey
    data
    text
    <p>I'm developing some code which reads file names from an sd-card (using FatFs) and displays them to the screen. Here's a snipet of what I have working, this prints out the files on the card as expected - </p> <pre><code>FRESULT result; char *path = '/'; //look in root of sd card result = f_opendir(&amp;directory, path); //open directory if(result==FR_OK){ for(;;){ result = f_readdir(&amp;directory, &amp;fileInfo); //read directory if(result==FR_OK){ if(fileInfo.fname[0]==0){ //end of dir reached //LCD_UsrLog("End of directory.\n"); break; } if(fileInfo.fname[0]=='.')continue; //ignore '.' files TCHAR *fn_ptr; //file name, why a pointer? fn_ptr=&amp;fileInfo.fname; //get file name LCD_UsrLog("%s\n",fn_ptr); for(delay=0;delay&lt;0x0FFFFF;delay++){ShortDelay();} //delay to display }//end result==fr_ok }//end for }//end result==fr_ok </code></pre> <p>Where</p> <pre><code>typedef char TCHAR </code></pre> <p>and </p> <pre><code>typedef struct { DWORD fsize; /* File size */ WORD fdate; /* Last modified date */ WORD ftime; /* Last modified time */ BYTE fattrib; /* Attribute */ TCHAR fname[13]; /* Short file name (8.3 format) */ </code></pre> <p>} FILINFO;</p> <p>I need to copy the names of the files into an array for processing however I've tried a few ways but can't seem to get the array working. I have tried creating an arbitrarily large array of TCHARs and dereferencing the file name pointer but this prints garbage.</p> <pre><code>FRESULT result; char *path = '/'; //look in root of sd card TCHAR fileList[50]; u32 index=0; result = f_opendir(&amp;directory, path); //open directory if(result==FR_OK){ for(;;){ result = f_readdir(&amp;directory, &amp;fileInfo); //read directory if(result==FR_OK){ if(fileInfo.fname[0]==0){ //end of dir reached //LCD_UsrLog("End of directory.\n"); break; } if(fileInfo.fname[0]=='.')continue; //ignore '.' files TCHAR *fn_ptr; //file name, why a pointer? fn_ptr=&amp;fileInfo.fname; //get file name fileList[index]=*fn_ptr; LCD_UsrLog("%s\n",fileList[index]); for(delay=0;delay&lt;0x0FFFFF;delay++){ShortDelay();} //delay to display index++; }//end result==fr_ok }//end for }//end result==fr_ok </code></pre> <p>I suspect this is a simple mistake regarding pointers or the proper usage of an array of chars but it has been 4+ years since I've last touched C and I'm lost!</p> <p>Any help would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload