Home > other >  I cannot read files from Turkish character directory in C
I cannot read files from Turkish character directory in C

Time:10-11

In C Programming; I cannot read files from a directory with Turkish characters, but if I change the name of the folder containing Turkish characters, I can read them.

  1. Os Name: Windows 10
  2. Programming Language: C
  3. IDE: Visual Studio Code

I have folder named Ülke. I cannot read files from this directory.

DIR *dr = opendir("C:/Users/softeng/tutorials/comp/Ülke/");

but When I rename this folder to Ulke, I can read it.

DIR *dr = opendir("C:/Users/softeng/tutorials/comp/Ulke/");

All Code;

#include <stdio.h>
#include <dirent.h>
#include <locale.h>
  
int main(void)
{
    setlocale(LC_ALL, "Turkish");
    struct dirent *de;
    DIR *dr = opendir("C:/Users/softeng/tutorials/comp/Ülke/");
  
    if (dr == NULL) {
        printf("Could not open current directory" );
        return 0;
    }
  
    while ((de = readdir(dr)) != NULL)
        printf("%s\n", de->d_name);

    closedir(dr);    
    return 0;
}

How can i solve it.

CodePudding user response:

Vs Code >Preferences>Settings

Then;

Search

Files Encoding:

You can choose ISO-8859-9

And setlocale(LC_ALL="Turkish")

CodePudding user response:

setlocale(LC_CTYPE, "en_US.UTF-8") setlocale(LC_CTYPE, "turkish") setlocale(LC_CTYPE, "iso-8859-9")

you can try these code.

  • Related