Note that there are some explanatory texts on larger screens.

plurals
  1. POReading mutiple files from a directory
    primarykey
    data
    text
    <p>I am having difficulty to open files from a directory which is in different folder than the exe. I have managed to read one file. But how to read multiple files present in the directory in loop using program.</p> <p>The code used for the single file processing is below:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; int main() { FILE *fp, *tp, *tl; char str_buff[1024] = { FALSE }; char str[125]; char strlengths[MAX_NO_OF_STRINGS]= { FALSE }; //int Result; //int string_startflag = FALSE; int string_cntr = FALSE,i = 0, n = 0; fp = fopen("D:/folder/language/stringEnglish.h", "r"); tp = fopen("New Text Document.txt", "w"); // open the file to Write tl = fopen("New Length Document.txt", "w"); // open the file to Write lengths while (NULL != fgets(str_buff, sizeof(str_buff), fp)) { sscanf(str_buff, "%*[^\"]%*c%[^\"]%*c%*[^\n]%*c", str); //printf("%s\n", str); if (string_cntr &gt; 6) { if (string_cntr&lt;= MAX_NO_OF_STRINGS) { fprintf(tp, "%s\n", str); strlengths[i] = strlen(str); i++; } } string_cntr++; } for(n=0;n&lt;(MAX_NO_OF_STRINGS-6);n++) { fprintf(tl,"%d\n",strlengths[n]); } fclose(fp); fclose(tp); fclose(tl); return 0; } </code></pre> <p>So I'm able to process file to parse the variables in the file and get the lengths of the strings. Problem is how to open multiple files I have file names in the folder language as:</p> <pre><code>stringItalian.h,stringLatvian.h,stringSlovakian.h,stringSlovenian.h,stringSpanish.h,stringSwedish.h,stringTurkish.h,stringUkrainian.h </code></pre> <p>How can I open files of these names in a loop?</p> <p>Also is there any way to give the path of the folder <code>D:/folder/language</code> in general way?</p> <p>Thanks in advance.</p>
    singulars
    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.
    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